Re: [gtk-list] Re: fork() / execl()



As the well known Erik Mouw said...
->On Tue, 25 May 1999 11:08:56 +0200 (MET DST), gtk-list@redhat.com (Emmanuel DELOGET) wrote:
->> As the well known Daniel J. Kressin said...
->> ->Also, the child should exit with _exit() rather
->> ->than exit(), correct?
->> 
->>      Exit() just works until you don't register atexit function
->>      that free() something wrong (and so on). Basically, exit()
->>      calls all atexit registered functions, flushes streams, closes
->>      opened streams, destroy temp files than calls _exit(), which
->>      close opened FDs, send SIGCHLD to its parent (if one exists),
->>      do some tricky stuff to have its sons be the init daemon sons,
->>      and send SIGHUP and SIGCONT to others.
->
->[note: this is becoming off topic, but it's fun ;-)]

[continue: off-topic (should we create a gtk-off-topic-list@redhat.com ?]

->
->After the atexit functions, everything is handled by the kernel. So the
->kernel closes all FDs which are still open, sends a SIGCHLD to its parent.
->The parent has to call wait() or waitpid() to get the exit status of the
->child (this can be done in a SIGCHLD signal handler). As long as the
->parent doesn't collect the status of the child, the child's process table
->will be kept in memory by the kernel; that's what we call a zombie
->process.
->
->The tricky stuff about the child's child processes isn't tricky at all:
->In a process table entry is a list of its child processes. If a process
->dies, the kernel cleans up it's process table, and set the PPID (parent
->process ID) of each child to the PPID of the parent's parent
->(grandparent). If the grandparent also died, they will get the PPID of the
->grandparent's parent (greatgrandparent). As init is the "mother of all
->processes" and supposed to run forever, init will clean up all zombies.
	Of course it is not tricky. I just didn't want to add 5 lines to my 
	previous mail :)

->
->I'm not sure if the kernel also sends SIGHUP/SIGCONT to the child
->processes, I can't find evidence[1] on that. My experience is that it
->doesn't.

	The infos I gave come from the freebsd manpages for exit() and 
	_exit().
	By looking at the kernel of freebsd/netbsd :
	[the code come from kern_exit.c, and lies in the exit1() function
	which is called by the exit syscall - comment snipped]
-------------------------------------------------------------------------------
        if (SESS_LEADER(p)) {
                register struct session *sp = p->p_session;

                if (sp->s_ttyvp) {
                        if (sp->s_ttyp && (sp->s_ttyp->t_session == sp)) {
                                if (sp->s_ttyp->t_pgrp)
                                        pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
                                (void) ttywait(sp->s_ttyp);
                                if (sp->s_ttyvp)
                                        vgoneall(sp->s_ttyvp);
                        }
                        if (sp->s_ttyvp)
                                vrele(sp->s_ttyvp);
                        sp->s_ttyvp = NULL;
                }
                sp->s_leader = NULL;
        }
------------------------------------------------------------------------------- 
In the man page of _exit states :
------------------------------------------------------------------------------- 
     o   If the termination of the process causes any process group to become
         orphaned (usually because the parents of all members of the group
         have now exited; see ``orphaned process group'' in intro(2)),  and if
         any member of the orphaned group is stopped, the SIGHUP signal and
         the SIGCONT signal are sent to all members of the newly-orphaned pro-
         cess group.

      o   If the process is a controlling process (see intro(2)),  the SIGHUP
         signal is sent to the foreground process group of the controlling
         terminal, and all current access to the controlling terminal is re-
         voked.
------------------------------------------------------------------------------- 
	This is a posix stuff - and therefore should be in linux and others too.

	Yours,
->
->Erik
->
->[1] W. Richard Stevens, "Advanced programming in the UNIX environment",
->    Addison-Wesley
->
->-- 
->J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
->of Electrical Engineering, Faculty of Information Technology and Systems,
->Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
->Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
->WWW: http://www-ict.its.tudelft.nl/~erik/
->
->
->-- 
->To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
->


-- 
__________________________________________________________________________
   Emmanuel DELOGET [pixel] pixel@{dotcom.fr,epita.fr}  ----  DotCom SA
         http://www.epita.fr/~pixel | http://www.dotcom.fr/~pixel
"On the last day, God created Linux. And Microsoft won its antitrust case"
--------------------------------------------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]