Xref: utzoo comp.unix.questions:14094 comp.unix.xenix:6266 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!ispi!jbayer From: jbayer@ispi.UUCP (Jonathan Bayer) Newsgroups: comp.unix.questions,comp.unix.xenix Subject: Re: help determining child process status Message-ID: <624@ispi.UUCP> Date: 7 Jun 89 14:18:14 GMT References: <1854@leah.Albany.Edu> Reply-To: jbayer@ispi.UUCP (Jonathan Bayer) Followup-To: comp.unix.questions Distribution: usa Organization: Intelligent Software Products, Inc. Lines: 56 In article <1854@leah.Albany.Edu> msb62@leah.albany.edu.UUCP (Mitch Baltuch) writes: >I am running SCO Xenix v2.3 on a Zenith Z386, using their v2.3 development >toolkit. My problem is that I have a parent task which forks a number >of tasks. Some of these tasks spawn other tasks based on asynchronous >events, so that the number and duration of these tasks cannot be determined. >I am looking for a way that a task can tell when all its children have >terminated. This is complicated by the fact that one or two processes may >not terminate by themselves and cannot be terminated until all other >processes have exited. I have not been able to find a convenient way to >accomplish this. Any suggestions? Yes. Read the man page for wait(). All you have to do is to set up a list of all the child processes that you have to wait for them to terminate, wait for each one, and then kill the rest. Some sample code follows. Please note that I did not write in any error-checking code. I leave that as an exercise for the reader. JB main() { int wait_list[100], kill_list[10]; int num_to_wait = 0, num_to_kill = 0; int x; /* spawn child processes here using fork, fill in appropriate list */ if ( (x = fork()) != 0) { wait_list[num_to_wait++] = x; } if ( (x = fork()) != 0) { kill_list[num_to_kill++] = x; } /* wait for those processes to terminate on their own */ while (num_to_wait--) wait( wait_list[num_to_wait] ); /* kill those you want to kill */ while (num_to_kill--) kill( kill_list[num_to_kill], 9 ); } -- Jonathan Bayer Beware: The light at the end of the Intelligent Software Products, Inc. tunnel may be an oncoming dragon 500 Oakwood Ave. ...uunet!ispi!root Roselle Park, NJ 07204 (201) 245-5922 jbayer@ispi.UUCP