On Sun, 2006-09-04 at 12:52 +0800, Practical Perl wrote:
> Hello,
>
> When I receive a signal (for example,TERM or INT) from terminal,I want to
> get the process exit immediately.But the process have some childs running,so
> he would tell the childs to exit before he exit.So I write a kill statement
> (used to kill childs) in parent's signal handler.For example:
>
> # defined in parent
> $SIG{TERM}=sub { kill TERM => keys %childs;exit 0};
>
> where %childs record all childs' PIDs.
>
> Does this signal handler correct?I don't see anyone defined another 'kill'
> statement in some a singal handler,so I'm comfused about it.
> Thanks.
The correct format for kill is:
kill TERM, keys %childs;
See `perldoc -f kill`. Yes, you can use kill inside a signal handler.
But when the parent dies, a HUP signal is send to all its child
processes. This happens even if the parent is `kill 9`.
You could do it this way:
END {
kill TERM, keys %childs;
}
which will kill the child processes regardless of how the program ended;
with the exception of `kill 9`, of course.
--
__END__
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>