5 =head1 NAME $RCSfile: processrunning.pl,v $
7 Checks to see if a process is running
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Dec 13 09:13:27 EST 2010
27 $Date: 2013/05/21 16:42:17 $
33 Usage processrunning.pl: [-u|sage] [-ve|rbose] [-deb|ug]
37 -u|sage: Displays usage
40 -deb|ug: Output debug messages
42 -name: Name of the process to check for.
46 This script will simply check to see if the process specified is running. Note
47 that it uses ps(1) and relies on the presence of Cygwin when run on Windows
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
64 my $VERSION = '$Revision: 1.2 $';
65 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
70 my ($status, @output) = Execute "$restart 2>&1";
73 display "Successfully executed restart option: $restart";
75 display $_ foreach (@output);
77 display "Unable to restart process using $restart (Status: $status)";
79 display $_ foreach (@output);
86 error "Cannot use $FindBin::Script when using Windows - hint try using Cgywin", 1
87 if $ARCH eq 'windows';
92 usage => sub { Usage },
93 verbose => sub { set_verbose },
94 debug => sub { set_debug },
96 'restart=s' => \$restart,
97 ) or Usage "Invalid parameter";
99 Usage 'Extraneous options: ' . join ' ', @ARGV
102 Usage "Must specify process name"
106 verbose "$FindBin::Script V$VERSION";
108 my $opts = $ARCH eq 'cygwin' ? '-eWf' : '-ef';
110 my $cmd = "ps $opts | grep -i '$name' | grep -v \"grep -i \'$name\'\"";
112 my ($status, @output) = Execute $cmd;
115 display "No process found with the name of $name";
117 $status = restart $restart if $restart;
120 } elsif ($status == 2) {
121 error "Unable to execute $cmd (Status: $status) - $!\n"
122 . join ("\n", @output), $status;
127 if /grep -i '$name'/;
133 if /$FindBin::Script/;
135 display "Found processes named $name";
139 display "Did not find any processes named $name";
141 exit restart $restart if $restart;
145 =head1 CONFIGURATION AND ENVIRONMENT
147 DEBUG: If set then $debug is set to this level.
149 VERBOSE: If set then $verbose is set to this level.
151 TRACE: If set then $trace is set to this level.
159 L<Getopt::Long|Getopt::Long>
161 =head2 ClearSCM Perl Modules
173 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
174 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
179 =head1 BUGS AND LIMITATIONS
181 There are no known bugs in this script
183 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
185 =head1 LICENSE AND COPYRIGHT
187 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.