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
|
|
|
|
|
8
|
debug => 0, |
7
|
|
|
|
|
|
|
version => $VERSION, |
8
|
|
|
|
|
|
|
base => 'XAS::Base', |
9
|
|
|
|
|
|
|
mixins => 'proc_status', |
10
|
|
|
|
|
|
|
utils => 'run_cmd trim :validation', |
11
|
1
|
|
|
1
|
|
803
|
; |
|
1
|
|
|
|
|
1
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
636
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
168
|
|
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__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
XAS::Lib::Mixins::Process::Unix - A mixin for the XAS environment |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use XAS::Class |
76
|
|
|
|
|
|
|
debug => 0, |
77
|
|
|
|
|
|
|
version => '0.01', |
78
|
|
|
|
|
|
|
base => 'XAS::Base', |
79
|
|
|
|
|
|
|
mixin => 'XAS::Lib::Mixins::Process::Unix' |
80
|
|
|
|
|
|
|
; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This mixin provides a method to check for running processes on Unix. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 proc_status($pid) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Check for the running process. It can return one of the following status codes. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
6 - Stopped, either by a job control signal or it is being traced. |
93
|
|
|
|
|
|
|
5 - Uninterruptible sleep (usually IO) |
94
|
|
|
|
|
|
|
3 - Running or runnable (on run queue) |
95
|
|
|
|
|
|
|
2 - Interruptible sleep (waiting for an event to complete) |
96
|
|
|
|
|
|
|
1 - Defunct ("zombie") process, terminated but not reaped by its parent |
97
|
|
|
|
|
|
|
0 - Unknown |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item B<$pid> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The process id to check for. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L<XAS|XAS> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Copyright (c) 2012-2015 Kevin L. Esteb |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
124
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
125
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |