File Coverage

blib/lib/XAS/Lib/Mixins/Process/Unix.pm
Criterion Covered Total %
statement 6 19 31.5
branch 0 12 0.0
condition 0 3 0.0
subroutine 2 3 66.6
pod 1 1 100.0
total 9 38 23.6


line stmt bran cond sub pod time code
1             package XAS::Lib::Mixins::Process::Unix;
2              
3             our $VERSION = '0.01';
4              
5             use XAS::Class
6 1         7 debug => 0,
7             version => $VERSION,
8             base => 'XAS::Base',
9             mixins => 'proc_status',
10             utils => 'run_cmd trim :validation',
11 1     1   810 ;
  1         1  
12              
13 1     1   624 use Data::Dumper;
  1         2  
  1         158  
14              
15             # ----------------------------------------------------------------------
16             # Public Methods
17             # ----------------------------------------------------------------------
18              
19             sub proc_status {
20 0     0 1   my $self = shift;
21 0           my ($pid, $alias) = validate_params(\@_, [
22             1,
23             { optional => 1, default => "" },
24             ]);
25              
26 0           my $stat = 0;
27 0           my $cmd = "ps -p $pid -o state=";
28 0           my ($output, $rc, $sig) = run_cmd($cmd);
29              
30 0 0 0       if (defined($rc) && $rc == 0) {
31              
32 0           my $line = trim($output->[0]);
33              
34             # UNIX states
35             # from man ps
36             #
37             # D Uninterruptible sleep (usually IO)
38             # R Running or runnable (on run queue)
39             # S Interruptible sleep (waiting for an event to complete)
40             # T Stopped, either by a job control signal or because it
41             # is being traced.
42             # W paging (not valid since the 2.6.xx kernel)
43             # X dead (should never be seen)
44             # Z Defunct ("zombie") process, terminated but not reaped
45             # by its parent.
46              
47 0 0         $stat = 6 if ($line eq 'T'); # suspended ready
48 0 0         $stat = 5 if ($line eq 'D'); # suspended blocked
49             # $stat = 4 if ($line eq '?'); # blocked
50 0 0         $stat = 3 if ($line eq 'R'); # running
51 0 0         $stat = 2 if ($line eq 'S'); # ready
52 0 0         $stat = 1 if ($line eq 'Z'); # other
53             # $stat = 0 if ($line eq '?'); # unknown
54              
55             }
56              
57 0           return $stat;
58              
59             }
60              
61             # ----------------------------------------------------------------------
62             # Private Methods
63             # ----------------------------------------------------------------------
64              
65             1;
66              
67             __END__