[Linux-disciples] Killing child processes in Perl
Adam Rosi-Kessel
adam at rosi-kessel.org
Wed Jul 12 13:05:28 EDT 2006
You might look at the randomplay code, which I think deals with these same
issues. Hitting 'n' while randomplay is running kills all children; hitting
'q' kills children and the parent at once.
Stephen R Laniel wrote:
> I have a Perl script that invokes some subprocesses via
> system(). When I hit Ctrl+C while one of the subprocesses is
> executing, the subprocess dies but the master process keeps
> going. So then the master process moves on to the next
> system() call and executes that one. So I have to hit Ctrl+C
> again and again.
>
> I've done
>
> my $pid = $$;
> $SIG{'INT'} = sub { kill 9, $pid };
>
> in the master process, but that doesn't work: %SIG gets
> redefined in the subprocesses, so that SIGINT only gets sent
> to the subprocesses and not to the master process. How do I
> ensure that the master process traps all the signals for all
> its subprocesses?
>
> This seems to work, as a quick hack: put
>
> $SIG{'INT'} = sub { kill -9, getppid() };
>
> in each of the subscripts. getppid() gets the parent's
> pid, and kill -9, getppid() kills it. But I'd prefer not to
> have to add that to every subscript that the parent script
> might call.
>
> So is there any way to do something in the master script to
> trap all signals to its subscripts?
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Linux-disciples mailing list
> Linux-disciples at lists.bostoncoop.net
> http://lists.bostoncoop.net/mailman/listinfo/linux-disciples
More information about the Linux-disciples
mailing list