Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How can i check my script is already running?

by hotpelmen (Scribe)
on May 11, 2010 at 16:30 UTC ( [id://839473]=note: print w/replies, xml ) Need Help??


in reply to How can i check my script is already running?

Just a note: you need to exclude your "ps" check from the list of processes returned since it will also match your script path. Try this:
my @np = `ps aux | grep "/home/shekar/myscript.pl" | grep -v grep`; print "Number of running processes: " . (scalar @np) . "\n";
or
my $np = `ps aux | grep "/home/shekar/myscript.pl" | grep -v grep | wc -l`; chomp $np; print "Number of running processes: $np\n";
But I agree with others, you can find better ways to do it.

Replies are listed 'Best First'.
Re^2: How can i check my script is already running?
by Hue-Bond (Priest) on May 11, 2010 at 16:41 UTC
    Just a note: you need to exclude your "ps" check from the list of processes returned since it will also match your script path.

    I like to use the following trick, so as not to invoke an additional grep:

    $ ps aux | grep [i]nit root 1 0.0 0.0 23820 2024 ? Ss 08:23 0:01 /sbin +/init

    --
     David Serrano
     (Please treat my english text just like Perl code, i.e. feel free to notify me of any syntax, grammar, style and/or spelling errors. Thank you!).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://839473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-25 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found