Pipes between child processes in C

后端 未结 4 2022
旧时难觅i
旧时难觅i 2021-01-03 17:24

I\'ve seen this question before, but still a bit confused: how would I create communication between child processes of the same parent? All I\'m trying to do at the moment i

4条回答
  •  没有蜡笔的小新
    2021-01-03 17:55

    Rather than using un-named pipes, you may want to look into an alternate mechanism for inter-process communication such as using a FIFO, message-queue, or a socket using datagrams (i.e., UDP) that would allow you to write a "message" into the communication buffer, and then have another child read the message, see if it's for them and if it's not, have them place it back in the communicatons buffer for another child to read. Otherwise if the message is for them, they then accept it.

    Your message can be a struct that contains a sender ID, receiver ID, and then some buffer to hold a message, whether that's a string-type, etc.

    The communications buffer can be setup by the parent, and inherited by the children.

提交回复
热议问题