Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding previous instance?

Status
Not open for further replies.

133tcamel

Programmer
Sep 22, 2002
137
IN
Hi,
how do I find the previous instance of my perl script?
The script is setup as a cron job and I don't want more than one copy of the script running at the same time..

the method i'm using now is that the script checks for a file.. if it exists then it exits otherwise it touches file when the script starts and removes it when done.. this works but there are many problem with this method :/

Is there any other way of doing it? using the pid ($$)? Not sure but can it be done by capturing the ps output?

any help will be appreciated.

---
cheers!
san.
 
San,

I think your ps approach is the right way to go. You will need to work your way through the process list looking for processes with the same name as yourself -- you will, remember, always find at least one process that matches.

open(PS, 'ps -ef|');
while(<PS>){
$count++ if /$process_name/;
}

print $count; # holds count of matching processes Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top