If you are using the basic approach you showed, you need to add fflush(out); after the fprintf line.
There is internal buffering within the process, so what you wrote with fprintf just sits in a buffer until some later event. Meanwhile, you hang in fscanf.
Quote:
Originally Posted by Felipe Reigosa
If I fork() and do one call in the parent and the other in the child it works fine.
|
The fact that one call was in the parent and the other in the child does not significantly change the situation.
But the fact that the fprintf in one was not followed by any stall prior to reaching some point (such as program exit) that forced a flush, is a significant difference.
In your full design, I assume the each process writing to the pipe will then do other things that might stall. So at any place where a process might stall after writing to the pipe, if you need what was written to be available to the other process during that stall, you need to fflush it before the stall.