Re: the best form to wait the finish of execution of a child...

From: Florent Thoumie (flz_at_xbsd.org)
Date: 03/30/05

  • Next message: ALeine: "Re: A bunch of memory allocation bugs in CGD"
    To: zean zean <fbsd.hackers@gmail.com>
    Date: Wed, 30 Mar 2005 20:28:29 +0200
    
    
    

    Le Mercredi 30 mars 2005 à 14:17 -0400, zean zean a écrit :

    > Hi Hackers:
    >
    > Excuse for my badly English. which is the best form to wait the
    > finish of execution of a child.

            It depends on the context of your program
            (synchronous/asynchronous).

    > My idea is:
    >
    > pid_t chilpid;
    >
    > while(childpid != wait(&status))
    > ;

            That's a possibility, you can catch SIGCHLD with a signal
            handler (see signal(3), sigprocmask(2), sigaction(2)) which
            would set a global flag, and then use a non-blocking waitpid(2)
            or wait4(2) instead.

            Note: What you suggested isn't really safe. You shouldn't
            ignore wait(2) return status (could be -1 because something
            unexpected happened, see ERRORS section from the manpage).

    -- 
    Florent Thoumie
    flz@xbsd.org
    
    



  • Next message: ALeine: "Re: A bunch of memory allocation bugs in CGD"

    Relevant Pages