On Jun 13, 7:10 pm, [EMAIL PROTECTED] (Owen) wrote:
> I thought there may have been a perl command like "getpid (program)" but it 
> doesn't seem so.
>
> The program below is the basis of what I want to do, but my question, Is 
> there a better way of getting the pid?
>
> TIA
>
> Owen
>
> ================================================
> #!/usr/bin/perl -w
>
> use strict;
>
> my $program = "vi";
> my $status  = `/bin/ps cat | /bin/grep $program`;
>
> if ( length($status) > 0 ) {
>     print "$status";                       #extract pid from here}
>
> else { print "$program not running\n" }    # start program
>
> ================================================

You probably want the Proc::ProcessTable module from CPAN:

#!/usr/bin/perl
use strict;
use warnings;
use Proc::ProcessTable;
my $t = Proc::ProcessTable->new();
my $pid;
for my $p (@{$t->table}) {
   $pid = $p->pid if $p->fname eq 'vi';
}
print defined $pid ? "vi's pid is $pid\n" : "vi is not running\n";
__END__

Hope that helps,
Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to