Created
March 5, 2009 19:52
-
-
Save wmoxam/74521 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 | |
def running?(pid) | |
begin | |
return Process.getpgid(pid) != -1 | |
rescue Errno::ESRCH | |
return false | |
end | |
end | |
processes = `ps aax --sort cp -o pid,pcpu,time,cmd | grep Rails` | |
MAX_TIME = 20 # minutes | |
processes.each do |process| | |
process.strip! | |
pid, pcpu, time, cmd = process.split(/\s+/) | |
hh, mm, ss = time.split(':') | |
next if mm.to_i < MAX_TIME | |
puts "Rogue: #{pid} uses #{pcpu}% cpu, alive for #{time}" | |
Process.kill('SIGUSR1', pid.to_i) | |
sleep 20 | |
if running?(pid.to_i) | |
puts "Process is still running, sending term signal" | |
Process.kill("KILL", pid.to_i) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment