22
Aug
07

killevery is what happens when programmers don’t sleep

A simple Ruby script to kill all processes with a specific name.

Looking back on what I’ve done after a night’s rest with mixed horror and amusement, it seems this script is completely and totally useless, unless you’re looking for a half-hearted reimplementation of killall in Ruby. Why the hell did I write this?

Download the script to /usr/bin (or wherever) and chmod +x ./killevery

#!/usr/bin/ruby
def killevery(victim, options)
	processes = `ps -A | grep #{victim}`.scan(/(d+) .*/)
	if processes.length > 0
		puts "Killing #{processes.length} processes named #{victim}"
		processes.each { |p|
			print `kill #{options} #{p}`
		}
	else
		puts "No processes are named #{victim}."
	end
end
if $*.length < 1
	puts "Kill every process named >name<. Takes the same parameters as killall"
else
	killevery($*.pop, $*.join(' '))
end

1 Response to “killevery is what happens when programmers don't sleep”


  1. 1 Martijn Engler Aug 22nd, 2007 at 10:25 am

    The -signs are converted to their HTML entities (> and <) in your post. I accidentally replaced the < with a > so it wouldn’t work here at first.
    Now it seems to work fine, nice script ! :)

Got something to say?





RSS Latest tweet

  • logankoester: Locked out of my apartment... Woops

Flickr Randomness

www.flickr.com

Netflix Queue


EveningMama's BoyRainbow Brite and the Star StealerThe Brazilian JobThe Gene GenerationParty Monster