I've been trying to kill a process but all my options give me a Windows Access Denied Error.
I open the process(a python script) through test= subprocess.Popen([sys.executable, "testsc.py"])
and I want to kill that process.
So far, I've tried os.kill(pid, signal.SIGILL)
, os.kill(pid, 9)
, test.Terminate()
and simply test.kill()
. All of these give me the error.
I am using Python 2.7.1.4 on a Windows 7 x86 machine. I would appreciate the help! Thanks!
A workaround if anyone interested - even as an admin I get access denied on some services when using os.kill
. however, this works:
import subprocess
subprocess.check_output("Taskkill /PID %d /F" % pid)
So if you don't care about being cross-platform and want a quick and dirty solution - try this instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With