#!/usr/bin/perl

use strict;
use warnings;
use Proc::ProcessTable;

my $impna=shift // die "I need the impna.";
if(not ($impna eq 'nep' or $impna eq 'sos' or $impna eq 'bims')) {
  print "I am not aware of your impna $impna\n";
  exit;
}

my $type=shift // 'ernad';

my $name="$impna".'_'.$type.'.fcgi';

my $t = new Proc::ProcessTable;
my $count_kills=0;
foreach my $got ( @{$t->table} ) {
  my $line= $got->cmndline;
  #print "command '$line'\n";
  if(not $line=~m|$name|) {
    #print "found $line\n"; 
    next;
  } 
  my $pid=$got->pid;
  #print "found process to kill $line\n"; 
  system("kill -9 $pid");
  $count_kills++;
}

if($count_kills) {
  print "$count_kills killed\n";
}

