Advertisement
johnmahugu

python - kill a process by its name

Jul 2nd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. #a python script to kill process by its name
  2. # kill_process.py
  3. import os, signal
  4.  
  5. def check_kill_process(pstring):
  6.     for line in os.popen("ps ax | grep " + pstring + " | grep -v grep"):
  7.         fields = line.split()
  8.         pid = fields[0]
  9.         os.kill(int(pid), signal.SIGKILL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement