#!/usr/bin/perl

#
# OpServices Tenologia da Informacao
# @author Junior Cunha
# @version 1.0
# @date 13/03/2007
#
# @description
#    
#

use strict;

our ($process) = @ARGV;
our $ps_command = "/bin/ps axwo 'stat uid pid ppid vsz rss pcpu comm args'";

sub main {

   my @lines = grep { $_ =~ /$process/i and $_ !~ /$0/ } `$ps_command`;

   if ($#lines<0) {
      print "Ok - Process \'$process\' not running.\n";
      exit(0);
   }else{
      my $output;
      foreach my $l (@lines) {
         #print $l;
         chomp($l);
         my @parts = split(/[ \t]+/, $l);
         $output .= "/ ($parts[2]) $parts[8] $parts[9] /";
      }
      print "Critical - ", $#lines+1, " processes with command name \'$process\'. $output\n";
      exit(2);
   }

}

&main();
