Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

25. Process Termination > Interactions Between fork(), stdio Buffers, and _exit...

Interactions Between fork(), stdio Buffers, and _exit()

The output yielded by the program in Example 25-2 demonstrates a phenomenon that is at first puzzling. When we run this program with standard output directed to the terminal, we see the expected result:

$ ./fork_stdio_buf
Hello world
Ciao

However, when we redirect standard output to a file, we see the following:

$ ./fork_stdio_buf > a
$ cat a
Ciao
Hello world
Hello world

In the above output, we see two strange things: the line written by printf() appears twice, and the output of write() precedes that of printf().

Example 25-2. Interaction of fork() and stdio buffering

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint