Quote:
But I don't see why it's necessary to restrict this to child processes. Why not a wait call that takes a process id and waits until it ends?
Two reasons:
1) Without a parent making a seperate list of all children it has fork()ed, there is no way for it to wait until ALL it's children have exited (c.f. wait() - doesn't take a parameter, will wait for ANY child to exit).
2) When a process has exited and been waited on, we say it has been 'harvested'. If two processes (possibly one malicious) try to harvest another process, it is arbitrary which one will harvest successfully. If the parent didn't manage it, it may return with an error code or worse, sit in an infinite loop. Keeping a child the parent's responsibility solves this problem.
(please note that under *nix systems another process can wait for an arbitrary process to exit (note perl code not C):
Code:
while(-e "/proc/$pid") {}
The important point is a non-parent process cannot harvest another.)