I have a subroutine which calls fork() to spread out jobs over processes. I fork() a process and dojob($job) for every $job, and wait() for all children to finish. It's working as expected...
However, now that I think about it more critically, this is obviously flawed b/c wait() waits for any child process, not necessarily those that were spawned by the subroutine. How should I group only relevant children? I don't think waitpid() is useful here since I don't know the order which the jobs will finish. Should I fork twice, once to create a 'controller' child, which itself forks the 'worker' grandchildren? What's the etiquette here?