Keeping an eye on hung system calls..

Nik Clayton nik at ngo.org.uk
Thu Jun 8 22:03:34 BST 2006


Dominic Mitchell wrote:
> On Tue, Jun 06, 2006 at 11:54:19AM +0100, Aaron Trevena wrote:
>> On 06/06/06, Toby Corkindale <tjc at wintrmute.net> wrote:
>>> Both methods are kind of ugly though.. The system() call is expensive 
>>> enough as
>>> it is (including it's own fork&exec), and I'd still need to find a 
>>> mechanism to
>>> make sure I can kill the system-child of the worker fork-or-thread, as 
>>> well as
>>> just the worker.
>> You could use Killfam to ensure a process and all it's children are
>> sent the kill signal.
> 
> That's what process groups are for in Unix.  Send the signal to a
> negative PID to kill that process and all its children.  You do have to
> ensure that you start the new process in a group, however.  Have a nose
> around in "perldoc POSIX".

Since I've just had to do exactly that, I thought I'd mention that the 
relevant call is POSIX::setsid().

   # fork(), error checking here

   if($pid == 0) { # In child
       setsid() or die "setsid: $!\n";  # Start new session, process group
       exec qw(command arg1 arg2 arg3);
       exit;                # Not reached (hopefully)
   }

   # Back in the parent
   if($timeout_has_fired) {
       kill 15, -$pid;      # -$pid == kill all processes in group
       wait;                # Or $SIG{CHLD} = 'IGNORE';
   }

N



More information about the london.pm mailing list