Skip to content

Instantly share code, notes, and snippets.

@marcoagner
marcoagner / kill_process.py
Last active May 11, 2022 20:11
Python script to kill a process by its name
import os, signal
def check_kill_process(pstring):
for line in os.popen("ps ax | grep " + pstring + " | grep -v grep"):
fields = line.split()
pid = fields[0]
os.kill(int(pid), signal.SIGKILL)