Task sync

Leslie Mikesell les at chinet.chi.il.us
Thu Jul 28 05:51:17 AEST 1988


In article <11658 at steinmetz.ge.com> davidsen at 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



More information about the Comp.unix.wizards mailing list