[ale] Only one process
Chris Fowler
cfowler at outpostsentinel.com
Fri Jun 4 13:11:45 EDT 2010
I've been thinking of ways to guarantee that there is only one process
of a script running.
pid file
process looks for pid file. If it sees one it validates that there
truly is a process at the pid. If not, it creates new pid file and
runs. If so, it sends out error message and exits.
The script is in perl so the what this would work is?
if(-f $pid_file) {
# Get the pid info
my $pid = `cat $pid_file`;chomp $pid;
# look for process running
if(-f "/proc/$pid/cmdline") {
# We may want to look at cmdline and validate it is really
# this script and not just a reused pid #
die "Process running at $pid already!\n";
} else {
unlink "$pid_file";
}
}
# Ready to go!
I'm just looking for what would be considered "The Right Way(tm)"
Chris
More information about the Ale
mailing list