1.- Create shared memory OK:
iIdentificador = shmget(5000,sizeof(int),IPC_CREAT | 0777); //5000 is the key.

2.-Connection 1 and view the integer shered OK:
piIntegerShared_1=(int *)shmat(iIdentificador,NULL,0))
printf("\n\t =>Dato compartido [%ld]\n",*piIntegerShared_1);

3.-Connection 1 and view the integer shered OK:
piIntegerShared_1=(int *)shmat(iIdentificador,NULL,0))
printf("\n\t =>Dato compartido [%ld]\n",*piIntegerShared_1);

4.-Connection 2: ERROR !!!:
if((piIntegerShared_2=(int *)shmat(iIdentificador,NULL,0))==(void*)-1)
printf("\n\n\t ERROR shmat memoria2 [%d] [%s]",errno,strerror(errno));


Output: ERROR shmat memoria2 [22] [Invalid argument]

The connection 2 only is ok, if we delete the connection 1 with:
shmdt(piIntegerShared_1);

Which is the problem?

Thanks,
David