Task sync

Ken Keirnan kjk at pbhyf.PacBell.COM
Wed Jul 27 09:15:54 AEST 1988


In article <11658 at steinmetz.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
>
>  I have a problem which requires running a number of similar programs,
>then a final program. It's not a make, but the solution might be applied
>there, too.
>
>  I want to start up to N tasks, and when I try to start the N+1th task
>I want to hang until at least one is done. I want to do this in a
>portable way which will run of reasonable BSD and USG systems.
>
>  I have a hack which more of less works under SysV using semiphores and
>stuff, but it's not portable, and a real kludge. If someone can give me
>a clue on a better way I'd be grateful.


A relatively easy way to accomplish this similar to the way "init" works.
Keep a table of the process IDs for each child process as it is created,
then perform a "wait()".  When wait returns, check the return value for fail
(no children to wait for) and then with each value in the table.  If the
return value is "fail", or a match is found in the table, drop through and
execute the final child process.  If you need to wait on all children
prior to executing the final process, keeping track of the children is not
necessary.  In this case simply loop until wait() returns error status.

Ken Keirnan
-- 

Ken Keirnan - Pacific Bell - {att,bellcore,sun,ames,pyramid}!pacbell!pbhyf!kjk
  San Ramon, California	                    kjk at pbhyf.PacBell.COM



More information about the Comp.unix.wizards mailing list