Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.cis.okstate.edu!news.ksu.ksu.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!newsfeed.internetmci.com!in2.uu.net!csnews!boulder!coopnews.coop.net!hops.entertain.com!usenet From: dwatson@abwam.com (Darryl Watson) Newsgroups: comp.unix.bsd.misc,comp.unix.bsd.bsdi.misc Subject: Re: BSD 4.4: Preventing zombies SIGCHLD Date: 21 Dec 1995 16:33:50 GMT Organization: ABWAM, Inc. Lines: 56 Message-ID: <4bc29e$m4n@hops.entertain.com> References: <4b47nt$e1a@picasso.op.net> <4b6een$667@noao.edu> <4b78mk$1t5@park.uvsc.edu> <4b8058$8gc@picasso.op.net> NNTP-Posting-Host: 199.45.153.182 X-Newsreader: WinVN 0.92.5 Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:394 comp.unix.bsd.bsdi.misc:1762 In article <4b8058$8gc@picasso.op.net>, root@candle.pha.pa.us (Bruce Momjian) says: > >Terry Lambert (terry@lambert.org) wrote: >: rstevens@noao.edu (W. Richard Stevens) wrote: >: ] >: ] > I am looking for a standard way of automatically preventing zombies by >: ] > auto-reaping exit'ed children. >: ] > I know SIGCLD works under System V, and I know I can install a SIGCHLD >: ] > handler to wait() after each child exit. >: ] >: ] The POSIX solution is to call waitpid() from a SIGCHLD handler, but you >: ] must call it in a loop with the WNOHANG option to avoid leaving any >: ] zombies around. Calling wait() can still leave zombies if multiple >: ] children exit() at about the same time. Here is what it takes: >: >: Not to contradict another Tucson resident, but I thought that >: ignoring the signal would cause it to be automatically reaped >: on exit? > >I believe this is true, but I thought that the process was a zombie >until the parent exits. > >I am embarased to say I asked this question because I am hacking acm >(the PD X F-16/Mig flight simulator) to use sox (the PD unix sound >generator) to generated flight sounds rather than use NETAUDIO or >HPAUDIO, which I don't have. (I will send the patches to the author.) > >Each time I want a sound, I vfork() and exec() a script that runs sox on >the sound file. Without a child reaper, each sound generates a zombie, >and depending on how long you can stay in the air, that could be lots of >them. > >I am somewhat embarased to have involved W. Richard Stevens and Terry >Lambert in such a trivial project, but hey, its a fun game. Got for it! It is my opinion that computers are primarily made for games, and everything else is secondary. ;) What I do is define a handler in the parent to trap a signal like USR1, then have the child, right before exit, send that signal to the parent. The USR1 handler simply calls wait(), which is quick, because there's one or children waiting to be 'reaped'. We've got an encrypted password server which uses this feature on a busy system; we can't afford to have children hanging around the house too long, you know! It works fine. > >I love to watch the plane fly as I type. Have I been working on >computers too long?:-) > >-- >Bruce Momjian | 830 Blythe Avenue >root@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026 > + If your life is a hard drive, | (610) 353-9879(w) > + Christ can be your backup. | (610) 853-3000(h)