[comp.unix.ultrix] How to clear zombie children while parent still alive.

long@castor.csg.uiuc.edu (Junsheng Long) (03/28/90)

Is that possible to clear all zombie children while the parent
is still in execution under SunOS? I had the parent process to call
signal(SIGCHLD, SIG_IGN). This should let init to clear the
terminated child automaitically, when the parent got a SIGCHLD.
But SunOS still kept all the zombies until the parent exited. 
Is SunOS different from other Unix systems in this regard? 
Is it possible to clear zombies in a SunOS environment? And how?

Thank you.

Junsheng

ables@lot.ACA.MCC.COM (King Ables) (03/28/90)

From article <1990Mar27.164632.18462@ux1.cso.uiuc.edu>, by long@castor.csg.uiuc.edu (Junsheng Long):
> Is that possible to clear all zombie children while the parent
> is still in execution under SunOS?

Check the wait3() system call.  The child process stays in the process
table as a zombie until the parent waits on it and gets some indication
that it's died.  Yes, in your case you probably don't care.  Neither did
I, so I just called wait3(0,WNOHANG,0) to clear the condition on all
child zombie processes.
-----------------------------------------------------------------------------
King Ables                    Micro Electronics and Computer Technology Corp.
ables@mcc.com                 3500 W. Balcones Center Drive
+1 512 338 3749               Austin, TX  78759
-----------------------------------------------------------------------------

mike@turing.cs.unm.edu (Michael I. Bushnell) (03/28/90)

You clear zombie children *only* by exiting (clearly out) or by doing
a wait().  Ignoring SIGCHLD doesn't change that, nor arrange to have
init clean them up.  What you want to do is have a signal handler for
SIGCHLD that loops on wait3() (nonblocking) until there are no more
exited children to collect.

	-mib
--
    Michael I. Bushnell      \     This above all; to thine own self be true
LIBERTE, EGALITE, FRATERNITE  \    And it must follow, as the night the day,
   mike@unmvax.cs.unm.edu     /\   Thou canst not be false to any man.
        CARPE DIEM           /  \  Farewell:  my blessing season this in thee!

eli@panda.uucp (Eli Taub/100000) (03/28/90)

> Is that possible to clear all zombie children while the parent
> is still in execution under SunOS? I had the parent process to call
> signal(SIGCHLD, SIG_IGN). This should let init to clear the
> terminated child automaitically, when the parent got a SIGCHLD.

Under System V signal(SIGCLD, SIG_IGN) tells the kernel not to create
Zombies. This is special because the default for SIGCLD (or SIGCHLD) is
to ignore the signal.

> But SunOS still kept all the zombies until the parent exited. 
> Is SunOS different from other Unix systems in this regard? 
> Is it possible to clear zombies in a SunOS environment? And how?

In SUN and other BSDs you Must catch the signal and issue a wait 
so that the Zombie is cleared up.

Eli Taub	
Contractor at IBM (till Sep. `90)
(512) 838-4810

gwyn@smoke.BRL.MIL (Doug Gwyn) (03/28/90)

if (fork() > 0) _exit(0);