in reply to Perl Forking : perform some action until child process dies
When I first looked at your question, I couldn't see the problem, you wanted to start something then wait "until" it was done (waitpid). Ok, er, oh...you want to some code to execute while you are in the wait call?
Er, um you'll need to have someone else do that cuz, you just told it to wait until it's done.
(or, like others have said, 1) waitpid is 'blocking' ....(that's what you wanted? No? Ooops...), so either use non-blocking form of waitpid OR have something else (process/thread) do the calculate loop. Depends on what the calc routine does and how it interacts with the existing program variables as to whether or not threads or a process would be better.
If you use the non-waiting form of 'waitpid', be sure to read the 'perlipc' manpage to get the right example to guard against "gotcha's", like signals dropping between the cracks.
Basically you have to use 'waitpid' IN a child process you setup before you fork. Examples are in the manpage.
|
|---|