[ale] Only one process

Chris Fowler cfowler at outpostsentinel.com
Fri Jun 4 13:43:34 EDT 2010


On Fri, 2010-06-04 at 13:30 -0400, Lightner, Jeff wrote:
> PIDs get reused in UNIX/Linux so you should probably put in some logic
> to test what process is running on the PID to be sure it is one you
> would expect for this.  
> 
> I recently did a similar exercise (in shell rather than perl) for some
> processes that I wanted to insure were running.  Just pipe the grep for
> the pid to a grep for text of expect process.
> 
> Alternatively you might store the static portion of /proc/<pid> info
> somewhere then check that later to be sure it is the same. (Shell
> scripts are a little tricky since they execute various commands so at
> any given moment when you check the pid you might see a different
> command being executed.)

The check is not going to be that big of a pain since perl makes this a
breeze.

/proc/<pid>/cmdline stores each argument separated by \0.

my $cmdline = `cat /proc/$pid/cmdline`; chomp $cmdline;
my @args = split "\0", $cmdline;

# Make sure args[0] is perl
goto STALE unless $args[0] =~ m/perl/;
goto STALE unless $args[1] =~ m/process\.pl/;
return 1 # Process running;

STALE:
unlink $pid_file;
return 0;





More information about the Ale mailing list