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...

Thanks,
jp.


####################################################
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";  
}



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

Reply via email to