sub pidKill { #----------------------------------------------------------- # USE: kills the last process seen in output of # ps. # (This begs to kill the wrong program.) # ARGUMENTS: $string containing program, arguments, and possibly a sudo in front. # RETURN: none #----------------------------------------------------------- my $program = shift; my (@output,$line); if ($program =~ /^sudo /) { $program=$'; } if ($program =~ / /) { $program=$`; } while ($program =~ /\//) { $program=$'; } @output = `ps -eo "%p %c" | grep $program`; foreach (@output) { $line = $_; } trim($line); # like chomp but can strip leading spaces too. $line=~/ /; $line = $`; #should have just the prog now. kill 'KILL' , $line; }