Multiple child processes reading/writing on the same pipe

前端 未结 2 1665
甜味超标
甜味超标 2021-01-14 15:13

I am currently learning sockets programming using C in a Linux environment. As a project I am attempting to write a basic chat server and client.

The intention is t

2条回答
  •  野的像风
    2021-01-14 15:42

    Each byte of data written to a pipe will be read exactly once. It isn't duplicated to every process with the read end of the pipe open.

    If you want the data duplicated to multiple destination processes, you have to explicitly duplicate the data. For example, you could have one "master" process that has a pipe to and from every "slave" process. When a slave wants to broadcast a message to the other slaves, it sends it to the master process, which loops around and writes it once to each pipe going to the other slaves.

提交回复
热议问题