From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,bee968b4f86bfc67 X-Google-Attributes: gidf678f,public From: dlewis@voicenet.com (Daniel Lewis) Subject: Re: How to ignore SIGCLD and not produce zombies? Date: 1996/09/16 Message-ID: <51kcqj$pjf@gnews2.voicenet.com>#1/1 X-Deja-AN: 180959304 references: <51c1if$58s@pt9201.ped.pto.ford.com> organization: Voicenet - Internet Access - (215)674-9290 newsgroups: comp.unix.osf.misc Bryan Miller (millerb@pt9526.ped.pto.ford.com) wrote: : I have a server that listens to a well know port and forks : off children upon request. Since the server cannot wait : for the children to die before going back to the port to : listen it produces defunct (zombie) processes. : Isn't there a way to start the server with SIGCLD set : to ignore? I currently stop the server periodically : to reap the defunct processes and then restart the server. : All ideas are welcome since this is causing untold pain : and angst ;-) : regards, : Bryan Bryan, You might consider installing a signal handler for your server whose function is to reap child processes. For your server process, (void) signal(SIGCHLD, reaper); "reaper" is: int reaper() { union wait status; while (wait3(&status, WNOHANG, (struct rusage *)0) >= 0) ; } This code is from Comer's book "Internetworking with TCP/IP", Vol III, pp 135 and 136. The idea is that the server goes about its business, and when a child dies, it receives SIGCHLD. The above signal handler is called, which does a "wait3", thus reaping the child proccess which has caused the signal. THe WNOHANG prevents the signal handler from blocking if something goes wrong. So, you have the wait3 being called on demand. The behavior of SIGCHLD and SIGCLD is subtly different on BSD, Posix, and System V systems and is also dependent on the call you use to assign the signal handler, there are at least three different ways of doing that as I recall, haven't looked into it for awhile. Stevens "Advanced Unix Programming" has a few pages on this around page 279. Dan L.