you are probably thinking of either truss, trace or strace, depending on what OS you are talking about. | [reply] |
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] |
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 | [reply] [d/l] |