Created
August 16, 2022 09:15
-
-
Save rajarsheem/071f36b7275100fb25bbf846406963f4 to your computer and use it in GitHub Desktop.
kill all zombie processes with a specific pattern in the filename
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
import os | |
import subprocess | |
import sys | |
pattern = sys.argv[1] | |
print(pattern) | |
out = subprocess.run(["ps", "aux"], stdout=subprocess.PIPE, text=True).stdout | |
out = str(out).split("\n") | |
out = list(filter(lambda x: pattern in x, out)) | |
pid = [x.split()[1] for x in out] | |
print("Processes: {}".format("\t".join(pid))) | |
for p in pid: | |
os.system("kill -9 {}".format(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example: python kill_zombie.py train
this will kill all process that has the name "train" in it.