[ale] Only one process

Lightner, Jeff jlightner at water.com
Fri Jun 4 13:51:12 EDT 2010


D'oh - on rereading your message I realize you're already using
/proc/pid.

As Emily Litella often said: "Never mind"

-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
Lightner, Jeff
Sent: Friday, June 04, 2010 1:30 PM
To: Atlanta Linux Enthusiasts - Yes! We run Linux!
Subject: Re: [ale] Only one process

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.)

-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
Chris Fowler
Sent: Friday, June 04, 2010 1:12 PM
To: ale at ale.org
Subject: [ale] Only one process

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



_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
 
Proud partner. Susan G. Komen for the Cure.
 
Please consider our environment before printing this e-mail or
attachments.
----------------------------------
CONFIDENTIALITY NOTICE: This e-mail may contain privileged or
confidential information and is for the sole use of the intended
recipient(s). If you are not the intended recipient, any disclosure,
copying, distribution, or use of the contents of this information is
prohibited and may be unlawful. If you have received this electronic
transmission in error, please reply immediately to the sender that you
have received the message in error, and delete it. Thank you.
----------------------------------

_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo



More information about the Ale mailing list