fork - C - named pipe for multiple forked children -
if have multiple children created fork(), , method of communication parent "named pipes", need multiple named pipes? 1 each child? or can make 1 , have parent read that?
basically, there else need do? understand if several children write same named pipe @ same time, might cause problem reading whole message single child. there way make sure writes atomic?
you can have several writers single pipe. however, communication between fork()ed children , parent, might not need named pipes @ all. named pipes visible in file system , can used communication between processes not parent/child.
about atomicity: if write less pipe_buf (no less 512 bytes, 4096 bytes on linux, limits.h), write atomic , there no mixing of messages different writers. if write more pipe_buf, don't rely on writes being atomic.
the pipe(7) manual page says that:
pipe_buf
posix.1-2001 says write(2)s of less pipe_buf bytes must atomic: output data written pipe contiguous sequence. writes of more pipe_buf bytes may nonatomic: kernel may interleave data data written other processes. posix.1-2001 requires pipe_buf @ least 512 bytes. (on linux, pipe_buf 4096 bytes.)
Comments
Post a Comment