Skip to content

Instantly share code, notes, and snippets.

@rajarsheem
Created August 16, 2022 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajarsheem/071f36b7275100fb25bbf846406963f4 to your computer and use it in GitHub Desktop.
Save rajarsheem/071f36b7275100fb25bbf846406963f4 to your computer and use it in GitHub Desktop.
kill all zombie processes with a specific pattern in the filename
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))
@rajarsheem
Copy link
Author

example: python kill_zombie.py train
this will kill all process that has the name "train" in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment