Created
January 23, 2012 20:12
-
-
Save marians/1665312 to your computer and use it in GitHub Desktop.
A rather simple script to kill stalled processes. Adapt the grep string in the PS_CMD variable to make it match your needs.
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
# coding: utf-8 | |
""" | |
Dieses Script beendet bestimmte Scraper-Prozesse, die | |
schon länger als einen Tag laufen. | |
""" | |
PS_CMD = 'ps -eo pid,etime,cmd|grep scrape_updated_dose_values.py' | |
DAYSLIMIT = 1 | |
import os | |
if __name__ == '__main__': | |
handler = os.popen(PS_CMD, 'r') | |
lines = handler.read().split("\n") | |
for line in lines: | |
parts = line.strip().split() | |
if len(parts) < 3: | |
continue | |
ageparts = parts[1].split('-') | |
if len(ageparts) < 2: | |
continue | |
pid = int(parts[0]) | |
days = int(ageparts[0]) | |
if days < DAYSLIMIT: | |
continue | |
command = " ".join(parts[2:]) | |
print "Killing", pid, "after", days, "days -", command | |
handler = os.popen('kill ' + str(pid), 'r') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment