CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
fork a process

 



aclhkaclhk
New User

Apr 28, 2009, 9:43 PM

Post #1 of 4 (571 views)
fork a process Can't Post

I am not familiar with process mgt. I would like to do the following:

- fork a process (the forked process will do something and create a file /tmp/completed.txt. Then, it terminates normally.
- main process checks the existance of /tmp/completed.txt
- if completed.txt exists within 5 minutes, main process continues
- if completed.txt do not exist within 5 minutes, the forked process is killed. Then, main process continues.

Pls kindly advise a sample code.


1arryb
User

Apr 29, 2009, 1:26 PM

Post #2 of 4 (568 views)
Re: [aclhkaclhk] fork a process [In reply to] Can't Post

Hi aclhkaclhk,

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.

Cheers,

Larry


(This post was edited by 1arryb on Apr 29, 2009, 1:48 PM)


FishMonger
Veteran / Moderator

Apr 29, 2009, 1:37 PM

Post #3 of 4 (567 views)
Re: [1arryb] fork a process [In reply to] Can't Post

Larry, that address appears to be a pirated copy of the cookbook. As far as I know the only legit source for online copies of O'Rielly books are from Safari (O'Rielly). Please remove that link.


KevinR
Veteran


Apr 29, 2009, 2:39 PM

Post #4 of 4 (561 views)
Re: [FishMonger] fork a process [In reply to] Can't Post


In Reply To
Larry, that address appears to be a pirated copy of the cookbook. As far as I know the only legit source for online copies of O'Rielly books are from Safari (O'Rielly). Please remove that link.


I can verify it is a pirated copy. I have seen that link on a number of forums over the years.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives