my $program_name = 'abc.pl';
my $data = `ps ax | grep perl`;
my @ara = $data =~ /perl\s+$program_name/g;
my $count = @ara;
print "$count\n";
Sometime it might be useful for you to know at the start of a program whether it's already running. You can get the name of your current Perl script/program from $0. If the name of your Perl script is program.pl, then $0 will contain program.pl. You can try
print $0;
Hope this tiny piece of code will be useful for you. :)
No comments:
Post a Comment