I'm using a python script to control tcpdump
. I can start a process of tcpdump
just fine from my script. However, when I want to kill the tcpdump
process via python:
import subprocess
pid = 9669 # pid of the tcpdump process
subprocess.call(["sudo", "kill", "-9", f"{pid}"])
I receive this error message:
kill: (9669): Permission denied
However, when I open a shell and enter sudo kill -9 9669
it kills the process just fine. The system is configured so that neither sudo tcpdump
nor sudo kill
will prompt for a password. To my understanding the subprocess.call
command and the terminal command should be identical, yet one works and the other doesn't. What am I doing wrong?