#!/usr/bin/perl my $sig; print "my pid: $$\n"; $SIG{TERM} = \&handler; while(1) { if ($sig) { last; } select(undef, undef, undef, .2); # sleep for .2 sec } # clean up here `echo $sig > /tmp/sig.out`; # to check after reboot if it caught it exit; sub handler { $sig = shift; }