Created
February 24, 2010 21:47
-
-
Save eschulte/313890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## reap long-running processes and all of their descendants | |
## | |
## (?_^ | |
## |\ ) | |
## |/_\ | |
## | |
def variants | |
%x{ps auxwww |grep -i "tmp/variant"}.split("\n").map{|l| $1 if l.match(/^[\S]+[\s]+([\d]+)[\s]+/)}.compact | |
end | |
def and_descendants(pid) | |
%x{ps ax -o pid,ppid |grep -i #{pid}}.split("\n").map{|l| $1 if l.match(/^([\d]+)[\s]+([\d]+)/)}.compact | |
end | |
old = [] | |
while true do | |
variants.select{|p| old.include?(p)}.each{|p| and_descendants(p).each{|p| %x{kill -9 #{p}}}} | |
old = variants | |
sleep 4 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment