Skip to content

Instantly share code, notes, and snippets.

@briandemant
Forked from wmoxam/gist:74521
Created April 13, 2009 20:18
Show Gist options
  • Save briandemant/94687 to your computer and use it in GitHub Desktop.
Save briandemant/94687 to your computer and use it in GitHub Desktop.
#!/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 [R]ails`
processes.each do |process|
process.strip!
pid, pcpu, time, cmd = process.split(/\s+/)
hh, mm, ss = time.split(':')
next if mm.to_i < 20
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