Created
November 3, 2011 10:01
-
-
Save ramontayag/1336175 to your computer and use it in GitHub Desktop.
Kill stuck imagemagick convert processes
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 | |
LIMIT=30 #limit on seconds | |
PROCESS="convert" #change to process u want to grep | |
COMMAND="ps -eo pid,cmd,etime" | |
process_list = `#{COMMAND} | grep #{PROCESS}` | |
process_list = process_list.split("\n") # make an array of process strings | |
process_list = process_list.select {|process| process !~ /grep/} # remove the grep process | |
process_list.each do |process| | |
process_id = `echo #{process} | awk {'print $1'}`.to_i | |
process_command = `echo #{process} | awk {'print $2'}` | |
process_time = `echo #{process} | awk {'print $3'}` | |
process_time_split = process_time.split(':') | |
process_time_minutes, process_time_seconds = process_time_split[0].to_i, process_time_split[1].to_i | |
process_started_ago_in_seconds = process_time_minutes * 60 + process_time_seconds | |
if process_started_ago_in_seconds > LIMIT | |
Process.kill 9, process_id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment