note
vsespb
Looks like it's known <a href="http://www.nntp.perl.org/group/perl.perl5.porters/2000/01/msg5237.html">problem</a> in perl.<br>
Also, similar issue [id://440900] <br>
<br>
Code can be simplified to<br>
<code>
$sub = sub { exec "perl $0" };
$SIG{INT} = $sub;
$SIG{USR1} = $sub;
while(1) {
print ++$counter, "\n";
sleep 1;
}
</code>
(if you press Ctrl-C, it restarts only once)<br>
Workaround for example in perldoc:
<code>
#!/usr/bin/env perl
use POSIX ();
use FindBin ();
use File::Basename ();
use File::Spec::Functions;
$| = 1;
# make the daemon cross-platform, so exec always calls the script
# itself with the right path, no matter how the script was invoked.
print STDERR "STARTED\n";
my $script = File::Basename::basename($0);
my $SELF = catfile($FindBin::Bin, $script);
# POSIX unmasks the sigprocmask properly
my $need_restart = 0;
$SIG{HUP} = sub {
print "got SIGHUP\n";
$need_restart = 1;
};
code();
sub code {
print "PID: $$\n";
print "ARGV: @ARGV\n";
my $count = 0;
while (++$count) {
sleep 2;
if ($need_restart) {
exec($SELF, @ARGV) || die "$0: couldn't restart: $!";
}
print "$count\n";
}
}
</code>
<br>
(i.e. need to call exec() outside of signal handler)<br>
<br>
And another workaround is posted above by McA [id://1058570]
1058565
1058644