HP3000-L Archives

September 1995, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ross Ridge <[log in to unmask]>
Reply To:
Ross Ridge <[log in to unmask]>
Date:
Tue, 5 Sep 1995 14:52:37 GMT
Content-Type:
text/plain
Parts/Attachments:
text/plain (41 lines)
Geoff Harper wrote:
>     Can someone explain where C's printf sends its data to, and how it
>arrives at selecting the destination?
 
Jim Wowchuk  <[log in to unmask]> wrote:
>Two things you might want to try with your sample code
>
>1) flush the printf buffers using fflush() function.
 
Good idea.
 
>2) terminate with an _exit() rather than the (implied) exit()
 
Bad idea.  The implied exit() *is* flushing the stdio buffers, otherwise
it wouldn't appear at all, instead of just out of order.  Calling _exit()
traditionally *doesn't* flush the stdio buffers, it just kills the process
without doing any C Library cleanup.  It's normally used in situations
like this:
 
        printf("forking off a child process");
        if (fork() == 0) {
                /* Setup child's enviroment */
                if (error) {
                        /* Oops... something failed. */
                        _exit(1);
                }
                execv(...);
        }
 
If exit() were used instead of _exit() in this example, it could result
in the message being printed twice, once in the parent process and once
in the child process.
 
                                                Ross Ridge
 
--
 l/  //   Ross Ridge -- The Great HTMU                         +1 519 883 4329
[oo][oo]  [log in to unmask]      http://csclub.uwaterloo.ca/u/rridge/
-()-/()/
 db  //

ATOM RSS1 RSS2