Linux – Writing on a FIFO with multiple processes

fifolinux

I need to make a named pipe with mkfifo. For instance:

mkfifo mypipe

I'm going to have a systemd service (a simple shell script) that read from the pipe and I will write on the same pipe calling another script (e.g. write-to-pipe.sh).

What if I have multiple instances of write-to-pipe.sh writing simultaneously on the pipe?
I mean, many users can execute write-to-pipe.sh. If two users try to write on the pipe at the same time, is it going to create trouble (like when two users try to write on a regular file (not pipe) and one overwrite the other) or not?

I hope this is not a duplicate, but I couldn't find an answer to this question…

Thanks

Best Answer

Here's a quick test I ran:

mkfifo foo
yes "Process 1 reporting" > foo & yes "This is process 2" > foo &
awk '!a[$0]++' < foo

And the output I got from awk:

Process 1 reporting
Process 1 reportThis is process 2
This is process 2
This is pring
Process 1 reportocess 2
ing
ocess 2
This is prProcess 1 reporting
Related Question