简体   繁体   中英

Issue with one system v message queue for multiple process read/write

I am developing a server program that serves multiple clients by multiple child processes. I use only one System V message queue to communicate between parent process and child processes. Each process will wait for message with mtype equals to process ID. Each child process only communicate to parent process. In parent process, I call msgrcv with flag IPC_NOWAIT to prevent being blocked to process other stuffs. With 2 child processes, it works as expect, but when number of child processes increases, the issue will happen as follow:

  • If I set flag on msgsnd to IPC_NOWAIT, some child processes cannot send message to parent process with error EAGAIN. If I add mechanism to re-send message with this kind of error, it still fails and parent process doesn't receive an message.
  • If I unset flag on msgsnd from IPC_NOWAIT, some child processes will be blocked in this call to msgsnd function. The parent process doesn't receive any message.

So:

  • How can I fix this issue?
  • If not, can you recommend me an architect to solve my problem?

My system is Centos 7. The message has size of 300 bytes.

Code is not given. Best is to check return values of failure and refer manpage . On gdb you can single step through to get to point where child process fails to send message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM