Catching termination of child process and system() call

Norman Diamond diamond at jit345.swstokyo.dec.com
Thu Jan 24 13:37:50 AEST 1991


In article <YANG.91Jan23133130 at newyork.nff.ncl.omron.co.jp> yang at nff.ncl.omron.co.jp (YANG Liqun) writes:
>In article <15745vrm at 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 at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.lang.c mailing list