c - What key to put on the receiver side of Linux message queues? -
i have created message queue , sender part creates , sends message message queue.
i have used ipc_private
key in msgget()
on sender side.
now question is, key use in msgget()
on receiver side ?
using ipc_private
on receiver side key in msgget()
not receive message , fails.
i should mention msgsnd()
in sender part indicates error (returns -1), when printing perror()
, output success
, message sent message queue , can seen using ipcs -q command @ terminal. don't know why happens.
if(msgsnd(msqid,&msgp,88,ipc_nowait) == 0) { perror("\nsend : msgsnd fail"); msgctl(msqid,ipc_rmid,buf); return 1; }
output : send : msgsnd fail: success
you going have use common key value between 2 independent processes ... using ipc_private
means not planning on sharing queue between 2 processes unless secondary process has been forked first process. because of forking operation, child inherent queue identifier parent process, using ipc_prvate
in scenario okay. because using ipc_private
creates unique key-value every call used in, scenarios have 2 independent processes, such server/client relationship, need create common key ... can either "magic number" share between processes not in-use queue, shared memory segment, etc., or can create key off common file in filesystem using ftok()
.
Comments
Post a Comment