Problem shmat in HP-UX. EINVAL Error

I have a process that need two active connections to the same zone of shared memory. But when i do the second call to shmat it give me error 22 (EINVAL). Only works ok the second call to shmat if i disconnect the first connection (shmdt)
In Sun,AIX and Digital, i don�t have this problem.

Steps: I�m going to shared a integer.

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

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

3�.-Connection 2: !!! shmat 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

The order of the arguments you gave to shmget is wrong...suggest you look at its man page.

5000 is the key_t key, the order is ok.

I dont hardcode the key but rely on the kernel giving me a unique value for it. That's why 5000 threw me off because I took it to be the segment size requested.
Try shmget(IPC_PRIVATE, sizeof(int), 0777) but if you want to hardcode shmid then try...

shmget(5000, sizeof(int), 0777 & IPC_CREAT);

Don�t worry by the 5000 (key_t), in the original source is not hardcode, this is only the example of the problem.
I have tested your solution: shmget(5000, sizeof(int), 0777 & IPC_CREAT);
and give me error in Step 1: ERROR crear memoria [2] [No such file or directory].

Remember that the first connection (step 2) works correctly, the problem is the second one.

Resolved problem:

cc DemoIPC.c -o -N DemoIPC
DemoIPC
chatr +as mpas DemoIPC

Why is there two thread going on at the same time, in two different forums, with the same topic by the same user?

We load in memory oracle tables. To read the tables, they have associate several indexes. so we have several shared memory segment:
1..n Data Segment
1..n Indexex Segment (1xIndex)
1 Control Segment: To control de access of the table in memory.

One process can need read the same table with different index. (similar to SQL access). And so i need one instance (connection to data segment) for each different index access.

The index segment connection will be different, but the data segment will be the same. It was the problem.

, And these tables can be read by different indexes,