![]() |
Checking number of instances running
....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 |
Re: Checking number of instances running
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 |
Re: Checking number of instances running
"Rene Scheibe" <Rene.Scheibe@Stud.TU-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. |
| All times are GMT. The time now is 09:07 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.