in reply to Re^2: Killing Forks
in thread Killing Forks
As I think about it a little, though, sending yourself a SIGTERM is a bit redundant, you could of course just 'die' or 'exit' in the SIGALRM handler.
Also...you're calling 'waitpid' in the child (which is odd) after a call to exit (which is odder).
The other way of doing this, of course, is to get the parent to periodically wake up (you can do this with waitpid and a sleep) and calculate if it should kill off a child (just store each pid's start time and kill off the old ones, maybe keeping them in a sorted list of age or something).
One case where you might need to have the parent do it is if your long-running code calls out to some XS code which doesn't return up to perl when it receives a signal.
Since perl 5.8, perl uses 'safe signals' by default, which means that your signal handlers only fire when control returns to the perl interpreter. This can be a long time (or never) when you call out of perl into C/XS code. (Safe signals are 'better', but you sometimes need to be aware of this issue when doing signal handling in perl).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Killing Forks
by Earindil (Beadle) on Aug 14, 2007 at 13:41 UTC | |
|
Re^4: Killing Forks
by Earindil (Beadle) on Aug 14, 2007 at 14:14 UTC | |
by jbert (Priest) on Aug 14, 2007 at 16:15 UTC | |
by cdarke (Prior) on Aug 14, 2007 at 16:18 UTC |