0

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.

Edward
  • 304
  • 2
  • 16
  • Probably your child app start subprocesses? See https://stackoverflow.com/questions/6549669/how-to-kill-process-and-child-processes-from-python – crayxt May 13 '16 at 10:34
  • Try passing `signal.SIGKILL` arguement in `p.kill()`. Not tried though. – Tanu May 13 '16 at 10:38

0 Answers0