Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

catch hup, restart

by thayer (Sexton)
on Dec 13, 2001 at 13:18 UTC ( [id://131572]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://131572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found