I'm trying to avoid killing the process like so:
import subprocess
command = "pkill python"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
but instead I'm trying to kill a particular process, not all python processes. Say that the process command is called "python test.py" I want to kill that one, and leave the other python processes intact. Not sure how I would go about doing this.
Platform is Linux/Ubuntu
To clarify, this is what I'm trying to accomplish, when I perform a ps -aux | grep "python" I see this:
sshum 12115 68.6 2.7 142036 13604 pts/0 R 11:11 0:13 python test.py &
sshum 12128 0.0 0.1 11744 904 pts/0 S+ 11:12 0:00 grep --color=auto test.py
I want to kill process 12115, but I'm not sure how I would go about doing this without killing all the other python processes at the same time.
EDIT: This is the solution that I came up with, but it doesn't look particularly elegant...
command = "ps aux"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0].split("\n")
try:
for p in output:
if "python test.py" in p:
l = p.split(" ")
l = [x for x in l if x!='']
pid = int(l[1])
os.kill(pid, 9)
except:
pass