use strict; my($startupTime) = time; # Setup system signal handlers $SIG{'TERM'} = 'SHUTDOWN'; $SIG{'INT'} = 'SHUTDOWN'; while(1) { sleep(10); } # Signal handler for SIGTERM sub SHUTDOWN { my($shutdownTime) = time; my($duration) = $shutdownTime-$startupTime; # Write out the shutdown time open(OUT, ">>$filename"); # Note: $$ is the process id for this script print OUT formatTime($shutdownTime)." Shutdown Uptime: ".formatDuration($duration)."\n"; close OUT; exit(1); }