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.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); }
If you are using threads, you could also use that mechanism to implement the timeout.
HTH, --traveler
In reply to Re: Hanging process activity
by traveler
in thread Hanging process activity
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |