multiple process kill in linux

By mentalglitch on Jun 15, 2008

run this in terminal and specify a mask such as "irc" and it will kill any processess with the word "irc" in it(all wild cards accepted)

#!/usr/bin/tclsh 

# note change the previous line to the location of your tclsh

catch {package require Tcl} pkgRet
if {[info exists pkgRet] && [string match "*can't find*" $pkgRet]} {puts "$pkgRet"; after 750 set done 1; vwait done; exit}

if {[llength [split $argv]] == "0"} {
 puts "mpkill <*mask ?f processes to kill*>"
 while {[llength [split [set a [gets stdin]]]] < 1} {
   puts "mpkill <*mask ?f processes to kill*>"
   set a [gets stdin]
 }
set argv $a
}
set found 0

catch {exec ps -x} ToScan
foreach fpid [split $ToScan \n] {
 if {[string match "$argv" $fpid] && ![string match "*$argv0*" $fpid]} {
  catch {exec kill -9 [lindex $fpid 0]} ret 
  puts "$ret"
  set found 1
 }
}

if {$found == 0} {puts "No Processes found matching your mask of \"$argv\""; after 750 set done 1; vwait done; exit}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.