Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool2.mu.edu!uunet!cai!davel From: davel@cai.uucp (David W. Lauderback) Newsgroups: comp.lang.c Subject: Re: Catching termination of child process and system() call Message-ID: <1991Jan24.084230.12153@cai.uucp> Date: 24 Jan 91 08:42:30 GMT References: Reply-To: davel@cai.UUCP (David W. Lauderback) Distribution: comp.lang.c Organization: Century Analysis Incorporated Lines: 57 In article yang@nff.ncl.omron.co.jp (YANG Liqun) writes: > >In article <15745vrm@cathedral.cerc.wvu.wvnet.edu> Vasile R. Montan writes: > >> ... I put the following in my main routine: >> >> void dowait() >>{ >> wait(0) > >It should be wait((int *)0). > This could be important, but probably isn't the cause of the left around processes. >>main() >> { >> ... >> signal(SIGCHLD, dowait); >> ... >> } > >When a child process stopped or exited, SIGCHLD signal will be sent to the >process and wait system call itself will catch the SIGCHLD signal from a >child. So you do not need to use >signal(SIGCHLD, dowait); >just use > wait(&ret_val) >in parent process. If he didn't wait until a signal came in, the parent process would stop until the child dies. This is probably not the desired effect. > >I think the problem of your code is that a SIGCHLD signal is sent to >parent process when a child process dies, but the signal is caught and >then invoke a wait system call which will wait for another SIGCHLD signal. > >Yang. > Calling wait returns when: a signal occurs OR when a child's status is ready OR when there is no outstand children. So the code above should work except for a timing problem if another signal come in, just as the process calls wait. However, if you are just trying to get rid of left-over child processes "zombie processes", just use: signal(SIGCHLD,SIG_IGN); instead of: signal(SIGCHLD, dowait); and you need no wait. (see signal(2) or signal(3c) in BSD) FYI: The zombie process is storing the child process' exit status, so must remain until its parent process has read this information. SIG_IGN to SIGCHLD states this process' child's return value should be discarded. -- David W. Lauderback (a.k.a. uunet!cai!davel) Century Analysis Incorporated Disclaimer: Any relationship between my opinions and my employer's opinions is purely accidental.