Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Hanging process activity

by traveler (Parson)
on Jul 29, 2002 at 21:49 UTC ( [id://186080]=note: print w/replies, xml ) Need Help??


in reply to Hanging process activity

Here is pseudo-code of what I do in a similar situation:
my_kill(){ $pid = shift; kill $pid; print "I killed $pid"; } ... if (($pid = fork()) == 0){ do_child_stuff; } else { // set a timeout. if pid does not die in 60 // seconds call my_kill with $pid as the arg wait_for_pid($pid, 60, &my_kill); }
wait_for_pid stores the pid, the function to call, and a time to call it in a hash. Each time a child dies it sends a signal (SIGCHLD) to me. I look through the list of children and remove those from the hash. I have a timer function running each second (I use gtk's scheduler for this as it is a gtk app) that, among other tasks, looks for processes that have not died in time and kills them. This has worked reliably for over a year. There are several variations you could use that might be more effecient for your environment.

If you are using threads, you could also use that mechanism to implement the timeout.

HTH, --traveler

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://186080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-13 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found