Path: utzoo!utgpu!attcan!uunet!husc6!rutgers!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.wizards Subject: Re: Task sync Message-ID: <6109@chinet.chi.il.us> Date: 27 Jul 88 19:51:17 GMT References: <11658@steinmetz.ge.com> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Distribution: na Organization: Chinet - Public Access Unix Lines: 19 In article <11658@steinmetz.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes: > > 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. > You didn't say if the tasks all start from the same parent or if the child processes can start new tasks also. If one parent starts all the processes, it should be able to just count them. Set up a signal handler for SIGCLD which does a wait() and decrements the process count, then re-enables the handler. If you reach the maximum tasks, just pause(). This should work at least in sysV, and unlike other signals, you should never miss a SIGCLD. If the child processes are allowed to fork() also, it becomes more complicated and you would need some form of IPC, perhaps a pipe inherited from the original parent. The child could write its PID down the pipe and wait for a signal before each fork(). Les Mikesell