Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If i do.

mkfifo /tmp/a
echo 'one'>/tmp/a

in the while from another terminal

echo 'two'>/tmp/a

and from a third terminal

more /tmp/a

Why i obtain as output of the last command this?

share|improve this question
up vote 7 down vote accepted


echo 'one' > /tmp/a

The shell does an open(O_WRONLY) on the pipe and then spawns echo which then does the write("one\n").

The open will block until some other process opens the pipe in RD_ONLY or RD_WR though.

And so will the open from your echo two.

So at the moment you do more /tmp/a you've got two processes ready to fire that have not opened the fifo yet let alone written anything to it. Which of those two will be scheduled as soon as more does the open(RD_ONLY) is going to be random.

To avoid blocking, you could do:

exec 3<>  /tmp/a

to unlock the pipe first, and then run your commands which won't block until the pipe is full.

Note however that the above will work on Linux but not on every Unix or Unix-like. The behaviour when opening a pipe in read-write mode is unspecified by POSIX.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.