On Mon, 30 Sep 2002 11:38:40 -0400, [EMAIL PROTECTED]
(Jean-Pierre Sylvanie) wrote:

>Hi guys,
>
>I want to do a sub that check if a process is sleeping
>or not...
>
>I wrote the following sub, but I was wondering if it
>was possible to to it without shell calls...

My top command dosn't allow for -U or $user. Maybe you
meant to use ps ?

>####################################################
>sub isSleeping{
>  
>  # get PID of process to check
>  my $pid = shift || return 0;
>
>  # get user name
>  my $user;
>  if(`id` =~ /\((\w+)\)/) {$user=$1};
>
>  # the 7th field (starting at 0) of top output is the state.
>  # top -b (for batch mode) -U $user (processes of $user).
>  my $state = (split /\s+/, (grep {/$pid/} `top -b -U $user`)[0])[7];
>  
>  return $state eq "sleep";  
>}
>

Try this Proc::ProcessTable method:
######################################################
#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;

my $t = new Proc::ProcessTable;

foreach my $p ( @{$t->table} ){
print $p->pid,"\t",$p->state,"\t",$p->cmndline,"\n";
}
#######################################################




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to