I noticed a few possible issues while reviewing your code.
First, you call msgget()
three times. Each time you use the same key stored in the variable send_key
. I believe this code should be:
send_msg_id= msgget(send_key, 0666 | IPC_CREAT);
send_msg_id1=msgget(send_key1, 0555 | IPC_CREAT);
send_msg_id2=msgget(send_key2, 0777 | IPC_CREAT);
Note the changing of send_key
to send_key1
in the second line and send_key
to send_key3
in the third line.
Second, the values 0666
, 0555
, and 0777
represent the permissions for the message queue. As described by the msgget() manual page:
Upon creation, the least significant bits of the argument msgflg define the permissions of the message queue. These permission bits have the same format and semantics as the permissions specified for the mode argument of open(2). (The execute permissions are not used.)
Thus, 0666
gives read/write permissions to all, 0555
gives read permissions to all, and 0777
gives read/write permission to all (the execute bit is ignored as noted in the manual page). This probably wasn't your intent. The simplest change would be to make these all 0666
for read/write (or 0600 if you want to restrict access to only your user). 0555
will be a problem as it is read-only. So, the above is further changed to:
send_msg_id= msgget(send_key, 0666 | IPC_CREAT);
send_msg_id1=msgget(send_key1, 0666 | IPC_CREAT);
send_msg_id2=msgget(send_key2, 0666 | IPC_CREAT);
Third, you only check the return codes for the first ftok
and msgget
calls. You should probably check the return code from all three to ensure there isn't a problem there.