0
votes

I am just learning about pipes, fifo and I have a question.

What happen if one program opens a pipe for reading and another program opens a pipe for writing. The two programs run in paralel. Let's say that the first program tries to read form pipe, but there is no information so it's block until the second program writes something.

In the second step, the first program is faster, and tries to read again form pipe. This time there is some information from the last time. What does the program do? Does it read the information from the last time?

Thanks!

2

2 Answers

2
votes

If I interpret your question correctly, the answer is NO. Any information read by the first read is consumed and no longer available in the pipe. If nothing further has been written to the pipe, the second read will block.

1
votes

Yes, the program which read from the pipe will read everything in the order as the other program has written it, but not necessarily in the same chunk sizes. And if there is something available, it will read it (or as much of it that fits into the read buffer).