Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Kill process by name instead of PID' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Kill process by name instead of PID
Authored by: adamjacobmuller on Jun 24, '03 02:25:43PM

a modification for pidof to kill....
the default is to send a sighup but you can kill too

ie ./kill name sig
place this script somewhere and chmod it 755
it's the perl version so the matching is better!
the base for this code came from someone who submitted a perl version as a comment to my bash&tr&awk pidof script, i forget his name but just want to make people know it's not entirely my own.. but heavily modified.

if ($ARGV[1]) {$sig=$ARGV[1]; } else { $sig=1; }
@procs = `ps -cxa`;
for $proc (@procs ) {
if( $proc =~ /\s+(\d+)\s+\S+\s+\S+\s+\S+\s+(\S+)/ ) {
$pid = $1;
$name = $2;
if( $name =~ /^$search$/ ) {
kill $sig,$pid;
print "$pid ";
print "\n";

[ Reply to This | # ]