I'm trying to use python psutil
library to create and kill process. My script starts an process, and then tries to kill started subprocess. I run same code under Windows and Linux. Under Windows everything works well. Under Linux psutils
starts subprocess correctly(so started app is script's child and it executed with same privileges as the script, but when I try to kill the process psutil
detaches from the process but not kills. Here is starting app code:
self.__proc = psutil.Popen(cmd, cwd=working_directory, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
After this I try to kill started child process:
self.__proc.kill()
self.__proc = None
I got same behavior using this:
while psutil.pid_exists(pid):
p = psutil.Process(pid)
if p is not None:
p.kill()
Can anyone explain why I can't kill process started by me? What I'm doing wrong?
I'm using Python 2.7.