in reply to SIGINT and system calls
You have a zombie problem. Call wait before exit in the signal handler.
You don't say what version of perl you use, but "safe" signals might be involved. That could prevent Ctrl-C from interrupting a blocking read in <CMD>. Your code looks fine.
You can break up the print <CMD>; by calling sysread, perhaps inside select.
It's a potential problem that the signal handler is set before the child is launched. That makes the child inherit a handler that is clearly meant for the parent. If you changed the kill signal to the more proper SIGINT, the child would try to signal a nonexistent child.# replaces print <CMD>; vec( my $rin, fileno(*CMD), 1) = 1; while (select my $rd = $rin, undef, undef, undef;) { my $bytes = sysread *CMD, my $buf, 4096; print $buf if 0 < $bytes; last if 1 > $bytes; } # wait added to lay the zombies sub myhand() { print "Parent $$ caught SIGINT.\n"; print "Parent $$ will KILL $pid.\n"; kill INT, $pid; waitpid $pid; exit 0; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: SIGINT and system calls
by Anonymous Monk on Jan 20, 2005 at 05:26 UTC | |
by Zaxo (Archbishop) on Jan 20, 2005 at 05:43 UTC | |
by Anonymous Monk on Jan 20, 2005 at 05:59 UTC | |
by Anonymous Monk on Jan 20, 2005 at 17:20 UTC |