How to restart a server based on a recieving a hup. The short answer is
$SIG{HUP} = sub { exec($0, @ARGV); };
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.
#!/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 "$!"; } }

Replies are listed 'Best First'.
Re: catch hup, restart
by IlyaM (Parson) on Dec 13, 2001 at 14:56 UTC