Path: utzoo!attcan!uunet!olivea!mintaka!bloom-beacon!deccrl!news.crl.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!jit345!diamond From: diamond@jit345.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: Catching termination of child process and system() call Message-ID: <1991Jan24.023750.19569@tkou02.enet.dec.com> Date: 24 Jan 91 02:37:50 GMT References: Sender: news@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit345.enet@tkou02.enet.dec.com (Norman Diamond) Distribution: comp.lang.c Organization: Digital Equipment Corporation Japan , Tokyo Lines: 47 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). It should be wait((union wait *)0) in BSD. I don't know what it should be in System V. >>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. wait() does not catch a signal. >So you do not need to use >signal(SIGCHLD, dowait); >just use > wait(&ret_val) >in parent process. This is true, he doesn't have to use signal(). However, he wants his main process to do other operations while the child is still running. If he calls wait() right away, then his main process is suspended. So he doesn't want to call wait() until after he receives a signal, when he knows that it will be a "short wait." >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. No, this is not the problem. His method is a common one. He has a problem with the system() library call misbehaving, and neither you nor I know the answer to that one. -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.