msgrcv pending forever !!!

When I am using msgrcv to get a message from a queue, in case of msgsnd some error, the msgrcv thread will waiting forever.
Is there some way that I can specify a time out value for this queue ? just let msgrcv wait for some time, if no message comes during this time slot, msgrcv just return failure.

Is there any one know that?

Thank you very much.

Checking it's manpage, I see one possible return value for it being 'EINTR -- while the process was sleeping to recieve a message, the process caught a signal.' So alarm() might be useful, if it'll cause it to return EINTR instead of killing the process.

I believe that the OP is looking to return from the msgrcv call if there is no message on the queue. Check the man page of msgrcv here.

So when calling msgrcv, set the msgflg variable to IPC_NOWAIT.

Hi, Create a thread to receive (msgrcv) the response.
Wait for certain time (letus say 5sec).
Send a reply (msgsnd) if and only if a flag is set to Success within this thread, after that much wait time.

Hav a gud time. :slight_smile: