[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Only one process
- Subject: [ale] Only one process
- From: cfowler at outpostsentinel.com (Chris Fowler)
- Date: Fri, 04 Jun 2010 13:11:45 -0400
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