For example, I created a named pipe like the following:
mknod myPipe p
And I read from it from some process (for example, some server). For example purposes, I used tail:
tail -f myPipe
If several client processes write some messages into it (for example, echo "msg" >> myPipe
, is there some chance that messages will get interleaved, like this:
<beginning of message1><message2><ending of message1>
Or is the process of writing to named pipe is atomic?
Best Answer
It depends on how much each process is writing (assuming your OS is POSIX-compliant in this regard). From
write()
:Also in the Rationale section regarding pipes and FIFOs:
The value if
PIPE_BUF
is defined by each implementation, but the minimum is 512 bytes (seelimits.h
). On Linux, it's 4096 bytes (seepipe(7)
).