how to tell when jobs are finished

Nicholas Henke henken at
Wed Aug 1 14:58:26 EDT 2001

Thanks guys for the input--
	I think the signal handler with a polling mechanism should work
very nice.


> Hi,
> I agree with Sean about the use of waitpid(). About the daemon, well, I think
> is not necesary. If I not  misunderstood you, what you want to do is execute
> a certain number of programs and know when anyone of those programs exited.
> Here is my proposal, in  the form of a pseudo-shell
> somehow the list of programs to execute
> 2. For each program to run, create a child using fork() (the master
> creates all the childs)
> 3. (optional) you may want to redirect each child output to some file
> 4. get from the childs its pid via some IPC mechanism (a pipe will do) and
> store the in an array or something (i would use a linked list, or a
> search-tree table if you will have lots of pids)
> 5. Finally, each child calls exec*() and replaces its memory image with the
> program desired - that is - executes the program
> 6. Now, you have to know when each of the programs you executed has exited.
> For simplicity, lets assume you whant to printf something like "Hey!, PID
> XXXX finished!". You can do this in two forms (to mi knowledge):
> 	a) loop until all the programs have exited. You can use waitpid with WNOHANG
> to poll each pid. Advantage: Simple.  Disadvantage: You can't do other
> productive things while waiting
> 	b) Set a signal handler to the alarm signal, and test say each second for
> completion of one of the pids in your list. If completion, print message and
> remove that pid from the list. Disable signal callback when list is empty,
> and re-enable when list has at leat one element. Advantages: You can do other
> productive things, like launching more processes. Disadvantages: A little
> more complicated. If you use this option, see sigaction(2) and signal(2)

Beowulf mailing list, Beowulf at
To change your subscription (digest mode or unsubscribe) visit

More information about the Beowulf mailing list