in reply to How do I determine if my script is already running?
And here's what the cron should execute:#!/usr/bin/perl open MY_PID, "> /tmp/do_stuff.pid" or die "can't write to /tmp/do_stuff.pid: $!"; print MY_PID $$; close MY_PID; # rest of code
You know, you could make it even simpler. Just have the program create a file, and make sure the file gets deleted in an END { ... } block, so that, if the program stops, the file goes away. That's not 100% safe though, since the file could be deleted by something else. So nevermind, don't do that. Do the previous stuff instead. If you want to.#!/usr/bin/perl open PID, "/tmp/do_stuff.pid" or spawn(); chomp(my $pid = <PID>); close PID; kill -HUP => $pid or spawn(); sub spawn { fork and exit; exec "/usr/bin/perl", "my_prog.pl"; }
|
|---|