Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Auto-restarting script if it dies

by zentara (Archbishop)
on Mar 09, 2007 at 13:41 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-01-24 00:55 GMT
Find Nodes?
    Voting Booth?