in reply to Signal to parent-process. Does it affect it's children?
I've made all this work, but every time I send a signal to it to get the current status it kills the current process
Well, not for the code below on my box. I've added/changed some bits.
use IPC::Open3; my $status; sub status () { print "Status is: $status\n"; $SIG{USR1} = \&status; } $SIG{USR1} = \&status; print "$$\n"; my @paths; my $c = 10; push @paths,"sleep ".$c++ for 0 .. 3; $c = 0; foreach $path (@paths) { print "loop ",++$c,"\n"; my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $path); $status = $path; waitpid($pid, 0); print "after waitpid\n"; }
Running it and killing the process several times yields
3297 loop 1 Status is: sleep 10 Status is: sleep 10 Status is: sleep 10 after waitpid loop 2 Status is: sleep 11 Status is: sleep 11 Status is: sleep 11
so yes, waitpid is re-entrant (at least on my box) and sending USR1 doesn't advance the loop and re-open CMD_* (which would kill the child process implicitly). Did you notice the line
print "Status is: $status\n";
above? Do you have unbuffered I/O on STDOUT?
update: yes, some signals get propagated to the children (USR1 isn't among them). Adding these bits to the script
sub default { print "got SIG ".shift()."\n"} $SIG{$_} = \&default for keys %SIG; $SIG{USR1} = \&status;
and invoking a perl script
#!/usr/bin/perl # have to print to a terminal directly, # since default file handles are re-directed open O ,'>', '/dev/pts/1'; sub default { my $sig = shift; print O "child Status: got SIG$sig\n"; $SIG{$sig} = \&default; } $SIG{$_} = \&default for keys %SIG; sleep $_ for 1..shift;
yields, killing the main script with <Ctrl>-C:
3437 loop 1 child Status: got SIGINT got SIG INT got SIG CHLD after waitpid loop 2 ...
You might want to wrap your call to open3() into a subroutine which resets $SIG{USR1} to 'IGNORE' using local. I suspect your problem being elsewhere. BTW, on which platform do you run?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Signal to parent-process. Does it affect it's children?
by rapide (Beadle) on Sep 07, 2008 at 21:47 UTC | |
by Perlbotics (Archbishop) on Sep 08, 2008 at 21:33 UTC | |
by rapide (Beadle) on Sep 09, 2008 at 15:45 UTC | |
by Perlbotics (Archbishop) on Sep 10, 2008 at 11:56 UTC | |
by Perlbotics (Archbishop) on Sep 10, 2008 at 15:19 UTC | |
| |
by rapide (Beadle) on Sep 10, 2008 at 14:25 UTC |