in reply to Re^2: protect children from SIG{INT}
in thread protect children from SIG{INT}

If a sleeping process catches any signal, it doesn't automatically resume sleep after the handler fires. Your process is exiting because it's done.

To sleep a specified time in spite of interrupts, you need to be prepared to resume sleep. One way in Perl,

my $span = 5; $span -= sleep $span while $span > 0;
The solution I gave would be improved by doing that wherever sleep 5 appears.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^4: protect children from SIG{INT}
by QM (Parson) on Nov 18, 2005 at 15:12 UTC
    $span -= sleep $span while $span > 0;
    Thanks, I had forgotten that sleep returns something useful!

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Re^4: protect children from SIG{INT}
by sgifford (Prior) on Nov 18, 2005 at 16:18 UTC
    It still looks to me like the exec is the problem:
    #!/usr/bin/perl $SIG{INT} = $SIG{HUP} = sub {}; exec 'perl', '-e', '$span=5; $span -= sleep $span while $span > 0; warn "Sleep is done\n";' or die 'exec failed';
    Hitting CTRL-C kills the process, and doesn't print Sleep is done, as it would if it had completed normally.

    Of course, using do instead would work, because it would avoid the exec.

    Does it even make sense for a signal handler to persist across an exec? A signal handler is basically an address in memory that the kernel should cause the user process to jump to if a signal arrives, but after an exec the address space will change, and the old address will almost certainly not be a sane place to jump to.