Path: utzoo!attcan!uunet!lll-winken!lll-lcc!lll-tis!ames!amdahl!pacbell!pbhyf!kjk From: kjk@pbhyf.PacBell.COM (Ken Keirnan) Newsgroups: comp.unix.wizards Subject: Re: Task sync Message-ID: <3690@pbhyf.PacBell.COM> Date: 26 Jul 88 23:15:54 GMT References: <11658@steinmetz.ge.com> Reply-To: kjk@pbhyf.PacBell.COM (Ken Keirnan) Distribution: na Organization: Pacific * Bell, San Ramon, CA Lines: 28 In article <11658@steinmetz.ge.com> davidsen@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@pbhyf.PacBell.COM