2

I've been reading about pipelining and also read this topic - How to send a simple string between two programs using pipes?

I read @jschmier answer (the first one) - and I wonder how does it actually work ? Do the programs writer.c and reader.c have to run simultaneously ? If they does , how reader.c is "informed" that writer.c has sent a string?

Those questions are mosly theoretical , but i'm really intrested to know how pipelining works. Thanks in adnvnace.

Community
  • 1
  • 1

1 Answers1

1
Do the programs writer.c and reader.c have to run simultaneously ?

They do.

If they does , how reader.c is "informed" that writer.c has sent a string?

Both programs open a special pipe device: "/tmp/myfifo. One opens for reading, and another one for writing. Kernel takes care of transferring data between them.

Please note, that pipes actually require concurrent reading and writing, as internal buffer is very small, and in absence of one activity blocks another.

How it works: if to simplify, the data written to a pipe goes from a process space into kernel and into reader process. Usually developers try to use non-blocking calls, as blocking program execution in case one process is busy is not acceptable.

For more information on pipes, you can read Linux documentation on the subject: http://linux.die.net/man/7/pipe

Valeri Atamaniouk
  • 5,125
  • 2
  • 16
  • 18
  • Thanks for the answer. I'd like to know - once the writer.c file writes to the pipeline , the reader.c file is getting an "alert" that new data has been written to the pipleine? Thanks again. –  Apr 17 '13 at 18:31
  • Yes, it works that way. Reader will receive data as soon as write writes it. There is no buffering invoked, as with stdio operations. – Valeri Atamaniouk Apr 17 '13 at 18:56