Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Auto-restarting script if it dies

by zentara (Archbishop)
on Mar 09, 2007 at 13:41 UTC ( [id://603985]=note: print w/replies, xml ) Need Help??


in reply to Auto-restarting script if it dies

Here is a little fun script, as an alternative to a temp file. I got the idea from Can't catch signals after an exec?
#!/usr/bin/perl use warnings; use strict; use POSIX(); $|=1; END { exec $0 } #needed to catch internal die's my $sub = sub { exec $0 }; # POSIX unmasks the sigprocmask properly my $sigset = POSIX::SigSet->new(); my $action = POSIX::SigAction->new( $sub, $sigset, &POSIX::SA_NODEFER ); POSIX::sigaction(&POSIX::SIGINT, $action); POSIX::sigaction(&POSIX::SIGUSR1, $action); POSIX::sigaction(&POSIX::SIGTERM, $action); # can still be killed with a kill -9 or SIGKILL # but kill -15 or SIGTERM will restart my $counter = 0; while(1){ print ++$counter,"\n"; if($counter == 4){die} sleep 1; } __END__

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-24 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found