signal not being caught when re-exec()d

  • Thread starter Jeff 'japhy' Pinyan
  • Start date
J

Jeff 'japhy' Pinyan

Here is a very simple demonstration of my problem:

#!/usr/bin/perl

BEGIN {
my @args = ($^X, $0, @ARGV);
warn "$$: [@args]\n";
$SIG{USR1} = sub {
warn "$$: re-exec()ing with [@args]\n";
exec @args;
};
}

while (1) { }

I call that code 'exec.pl', and run it thus:

% perl exec.pl arg &

and I get

1234: [/usr/bin/perl exec.pl arg]

Then I send it a USR1 signal (numerical value is 10):

% kill -10 1234

and I get

1234: re-exec()ing with [/usr/bin/perl exec.pl arg]
1234: [/usr/bin/perl exec.pl arg]

Then I try to send it the signal again... and nothing. No messages at
all. But the program is running, with the same PID... I'm baffled.
 
J

Jeff 'japhy' Pinyan

When the signal handler is triggered, the signal that caused it to run
gets blocked. The new program called with exec inherits the signal
mask, and therefore blocks the USR1 signal. To be able to catch it
again, you need to reset the signal mask. Use the POSIX sigprocmask
function:

use POSIX qw:)signal_h);

$sigset = POSIX::SigSet->new;
sigprocmask(SIG_SETMASK, $sigset);

Ah ha. Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top