Process.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« HTTP.pm ↑ Summary
1 package Watchdog::Process;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 0 ▶use Alias;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use Proc::ProcessTable;
6 use base qw(Watchdog::Base);
7 use vars qw($NAME $PSTRING $HOST $PORT);
8  
9 =head1 NAME
10  
11 Watchdog::Process - Check for process in process table
12  
13 =head1 SYNOPSIS
14  
15 use Watchdog::Process;
16 $s = new Watchdog::Process($name,$pstring);
17 print $s->id, $s->is_alive ? ' is alive' : ' is dead', "\n";
18  
19 =head1 DESCRIPTION
20  
21 B<Watchdog::Process> is an extension for monitoring processes running
22 on a Unix host. The class provides a trivial method for determining
23 whether a service is alive. I<This class has only been successfully
24 tested on Solaris 2.6>.
25  
26 =cut
27  
28 my %fields = ( PSTRING => undef, );
29  
30 =head1 CLASS METHODS
31  
32 =head2 new($name,$pstring)
33  
34 Returns a new B<Watchdog::Process> object. I<$name> is a string which
35 will identify the service to a human. I<$pstring> is a string which
36 can be used to identify a process in the process table.
37  
38 =cut
39  
40 sub new($$) {
41 my $DEBUG = 0;
42 my $proto = shift;
43 my $class = ref($proto) || $proto;
44  
45 my $self = bless($class->SUPER::new(shift,undef,undef),$class);
46 for my $element (keys %fields) {
47 $self->{_PERMITTED}->{$element} = $fields{$element};
48 }
49 @{$self}{keys %fields} = values %fields;
50 $self->{PSTRING} = shift;
51  
52 return $self;
53 }
54  
55 #------------------------------------------------------------------------------
56  
57 =head2 is_alive()
58  
59 Returns true if the service is alive, else false.
60  
61 =cut
62  
63 sub is_alive() {
64 my $DEBUG = 0;
65 my $self = attr shift;
66 my $t = new Proc::ProcessTable;
67  
68 for ( @{$t->table} ) {
69 # Proc::ProcessTable::Process::cmndline() seems to return
70 # undefined sometimes. Bug reported to author.
71 my $cmndline = $_->cmndline;
72 print STDERR "\$cmndline = $cmndline\n" if $DEBUG;
73 return 1 if defined($cmndline) && $cmndline =~ /$PSTRING/;
74 }
75 return 0;
76 }
77  
78 #------------------------------------------------------------------------------
79  
80 =head1 BUGS
81  
82 This class is I<unreliable> on Linux as
83 B<Proc::ProcessTable::Process::cmndline()> sometimes returns undef.
84  
85 =head1 SEE ALSO
86  
87 L<Proc::ProcessTable>
88  
89 =head1 AUTHOR
90  
91 Paul Sharpe E<lt>paul@miraclefish.comE<gt>
92  
93 =head1 COPYRIGHT
94  
95 Copyright (c) 1998 Paul Sharpe. England. All rights reserved. This
96 program is free software; you can redistribute it and/or modify it
97 under the same terms as Perl itself.
98  
99 =cut
« HTTP.pm ↑ Summary