in reply to Signals and subprocesses using fork, and system or exec.

I see a few problems.

Your system command error checking is wrong; it should be something like:

system("...") == 0 or die "...";
Also, Perl will automatically add /bin/sh -c if it's necessary, so you don't have to do that.

But I don't think that's your problem.

I also don't think it's a good idea to use $SIG{CHLD} = 'IGNORE'; and wait() together.

I don't think that's the problem, either.

Your sub declarations have parentheses after them, which creates a prototype. This prototype looks incorrect, and Pel issues a warning under -w.

And I don't think that's your problem either.

The problem I think you're having is that signal handlers are cleared when you use exec, and if you use system then $$ is the PID of the Perl process waiting for system to finish, not SSH. If you use exec, your HUP signal handler is cleared when ssh starts. If you use system, you kill ABRT Perl, doing nothing to the ssh process.

If you want to send an ABRT signal to ssh (and I think that's not the signal you want, since it usually causes a coredump), I think you should use exec in setupProcess, and send an ABRT signal in shutdown.

Replies are listed 'Best First'.
Re: Re: Signals and subprocesses using fork, and system or exec.
by exussum0 (Vicar) on Aug 26, 2003 at 03:53 UTC
    Switching to exec leaves ssh processes aboot. Though ... it does get rid of the "sh -c ssh". But from bash or tcsh, if you throw anything besides QUIT or TERM, it is supposed to get propogated.
    I've tried to make a process group, but that fails just as bad :(
    --
    Play that funky music white boy..
      I suggest that you use a second fork(), and then exec in the child process of that fork. Something like this in setupProcess:
      #!/usr/bin/perl -w use strict; my $sshpid = fork(); defined($sshpid) or die "fork error: $!"; if ($sshpid) { print "Parent PID is $$\n"; # Parent $SIG{HUP} = sub { warn "Aborting ssh pid $sshpid\n"; kill 'ABRT', $sshpid; exit(1); }; wait; exit(0); } else { # Child exec '/bin/sleep 6' or die "exec error: $!"; }

      I'm using an ABRT signal because that's what you used; I still don't think it's the right signal for this purpose, although I'm not sure what is if you can't use TERM.

        I'm not quite sure what you are accomplishing by second fork.
        --
        Play that funky music white boy..