The failure example demonstrates how one can
kill tasks and how one can find out when tasks exit or fail. For this
example we spawn several tasks, just as we did in the previous
examples. One of these unlucky tasks gets killed by the parent. Since
we are interested in finding out when a task fails, we call
pvm_notify() after spawning the tasks. The
call tells PVM to send the calling task a message when certain tasks
exit. Here we are interested in all the children. Note that
the task calling
pvm_notify() will receive the notification,
not the tasks given in the task id array. It wouldn't make much
sense to send a notification message to a task that has exited. The
notify call can also be used to notify a task when a new host has been
added or deleted from the virtual machine. This might be useful if a
program wants to dynamically adapt to the currently available
After requesting notification, the parent task then kills one of the
children; in this case, one of the middle children is killed. The call
pvm_kill() simply kills the task indicated by the task id parameter.
After killing one of the spawned tasks, the parent waits on a
pvm_recv(-1, TASKDIED) for the message notifying it the task has
died. The task id of the task that has exited is stored as a single integer
in the notify message.
The process unpacks the dead task's id and prints it out.
For good measure it also prints out the task id of the task it killed. These
ids should be the same.
The child tasks simply wait for about a minute and then quietly exit.