But doing an exec() in the signal handler didn't work after the first try for me. Here's a solution that is more careful and appropriate.$SIG{HUP} = sub { exec($0, @ARGV); };
#!/usr/local/bin/perl use strict; use vars qw($hup); $| = 1; $hup = 0; $SIG{HUP} = sub { $hup++; }; # handle the hup when convenient print "\n$0: args @ARGV, pid $$...\n"; while (1) { print "grinding away...\n"; sleep(5); if ($hup > 0) { exec($0, @ARGV) || warn "$!"; } }
In reply to catch hup, restart by thayer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |