Apr 29, 2009, 1:26 PM
Post #2 of 4
Re: [aclhkaclhk] fork a process
[In reply to]
Don't use completed.txt; loop on waitpid() in the parent after the fork(), sleeping a few seconds between calls. If you're still "wait"ing after 5 minutes, you can kill your child process (since you know it's pid from the return from fork(). Check out recipe 16.2 from the O'Rielly Perl Cookbook (link to pirate copy deleted) (pdf) or read the perlfork perldoc. Be advised that if this is production code, there are plenty of error cases to handle (e.g., restart-after-failure, double-start, race conditions, etc., etc.).
BTW, this seems like something that should have been wrapped into a module long ago. Anyone out there know of a lightweight asynchronous dispatch package? My short search came up dry.
(This post was edited by 1arryb on Apr 29, 2009, 1:48 PM)