in reply to Re^3: Signal to parent-process. Does it affect it's children?
in thread Signal to parent-process. Does it affect it's children?

Good comment!

I use kill -s HUP <pid> from the shell.
I've also tried to do this from a unaffected script with:
 kill "USR1", <pid>
So unless there are something I don't see here, Its not the problem :/

Replies are listed 'Best First'.
Re^5: Signal to parent-process. Does it affect it's children?
by Perlbotics (Archbishop) on Sep 10, 2008 at 11:56 UTC
    Why not kill -s USR1 <pid>? In your example, you only specified a handler for USR1, not HUP...

      Update: Because you said here, that you send a HUP, not a USR1.

      Sending a HUP to a process that isn't prepared to catch a SIGHUP will terminate. Exactly what you described and a lot of the helpful people here couldn't reproduce with USR1.

      You might like to add an additional HUP handler $SIG{HUP} = \&status; to print the status on HUP reception. But I would not recommend this, since HUP is a signal that will be send from the OS e.g. when the system is shut down or an interactive connection is closed. Using USR1 or USR2 is the usual way to do it.

      So the right way to get the status information would be kill -s USR1 <pid> (where <pid> is a positive integer). You could add a line like print "Status info: kill -s USR1 $$\n" to your program to get the correct PID without having to look for it.

      If that doesn't work, I do not have much more ideas... yet.

        I've re-produced a small example that hopefully gives you an idea of the problem. Copy past below and you are able to see it from my perspective. The point is that everytime you run "kill -s USR1 <pid>" you will see that processes gets killed.

        Put this content in "mainprogram" and 'chmod a+x'

        #!/usr/bin/perl -w use strict; use warnings; use IPC::Open3; use IO::Select; my($StartedProcess); $SIG{USR1} = \&status; sub status () { $SIG{USR1} = \&status; print STDERR "Currently running: $StartedProcess\n"; } # Opens external program, and as long as it exists, checks # if there is data in the pipe (STDOUT/STDERR) sub createProcess () { my($line, $selector, @ready, $fh); $StartedProcess = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, "./external.pp" +); close(CMD_IN); $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); while(@ready = $selector->can_read) { # do some operations on STDOUT/STDERR here } close(CMD_OUT); close(CMD_ERR); } my($pid) = fork; if($pid) { print "\t Created PID: $pid. run 'kill -s USR1 $pid'\n"; exit(0); } foreach(qw/1 2 3 4 5 6 7 8 9 10/) { createProcess(); } print STDERR "\n COMPLETED !"; exit(0);

        Put this content in "external.pp" and 'chmod a+x'
        #!/usr/bin/perl -w use strict; my $i = 0; while ($i <= 10) { sleep(3); $i+= 3; }
      I forgot it, but I've done the same with -s.

      Specify a handler for HUP? Why would I want to do that when all I want to use is USR1 ?