Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Checking number of instances running

Reply
Thread Tools

Checking number of instances running

 
 
Rene Scheibe
Guest
Posts: n/a
 
      08-07-2003
....what do you think about checking the number
of scripts (with a specific name) running by:

my $processname = 'script.pl';
my @log = split /\n+/, `ps ax`;
my $count = 0;
foreach (@log)
{
chomp;
if (/$processname/)
{
$count++;
}
}

Or is there a better solution?
I need this to check at startup of the script
if the max. number of instances i want to allow
is already reached and then to exit new
instances right after this test.

Thanks...
....Rene

 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      08-07-2003
Rene Scheibe wrote:

> ...what do you think about checking the number
> of scripts (with a specific name) running by:
>
> my $processname = 'script.pl';
> my @log = split /\n+/, `ps ax`;
> my $count = 0;
> foreach (@log)
> {
> chomp;
> if (/$processname/)
> {
> $count++;
> }
> }
>
> Or is there a better solution?
> I need this to check at startup of the script
> if the max. number of instances i want to allow
> is already reached and then to exit new
> instances right after this test.
>
> Thanks...
> ...Rene


You could do

my $processname = "script.pl";
$instances = `ps aux|grep $processname`;
exit if $instances;

That might be slightly faster

Pete
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      08-07-2003
"Rene Scheibe" <(E-Mail Removed)-Ilmenau.de> writes:
>> my $processname = "script.pl";
>> $instances = `ps aux|grep $processname`;
>> exit if $instances;

>
> this exits even if no instance of the script
> is running because "ps aux|grep script.pl"
> itself is shown as process. and using awk
> will slow down things i think.


$instances = `ps aux | grep $processname | grep -v grep | wc -l`
exit if $instances > $limit;

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM
Checking for duplicate instances of a script... Guillaume Dargaud Python 5 01-22-2004 04:43 PM
FOUND! how to attach to running instances of Internet Explorer gcash Python 3 08-03-2003 09:20 PM



Advertisments