#!/usr/local/bin/perl -w #----------------------------------------- # process killer #----------------------------------------- use strict; my %p_table = get_proc(); if (scalar keys %p_table >= 1) { for (keys %p_table) { my $pid = $_; my $msg = "\nPID : $pid : PROCESS :: $p_table{$pid} ::: KILL it ??? (y/n) : "; print $msg; while () { chomp; if ($_ =~ /^y$/i) { my $rc = kill 1, $pid; ($rc) ? print "killed OK\n" : print "didnt kill\n"; last; } elsif ($_ =~ /^n$/i) { last; } else { print $msg; next; } } } } else { print "No perl-ish processes found \n"; } #-------------------------------------------------- # format output from ps into only perl processes #-------------------------------------------------- sub get_proc { my %table; for (`ps -u richardh -o pid,args`) { chomp; if ($_ =~ /perl/) { my @ary = split / /, $_; my $var = shift @ary; unless ($var == $$) { $table{ $var } = join ' ', @ary; } } } return %table; }