1

I'm starting a Python subprocess with this command:

p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, start_new_session=True)

As per this answer, start_new_session=True (equvalent to preexec_fn=os.setsid) allows me to terminate the process with os.killpg(p.pid, signal.SIGTERM).

However, if command happens to be something like setsid sleep 10000, the process isn't terminated. In Python, how can I terminate subprocesses like these as well?

Community
  • 1
  • 1
IGNUcius
  • 83
  • 1
  • 6
  • possible duplicate of [how to get the ID of a process executed via setsid](http://stackoverflow.com/questions/16299784/how-to-get-the-id-of-a-process-executed-via-setsid) – dimo414 Apr 09 '15 at 01:06
  • Why are you using shell=True? – Padraic Cunningham Apr 09 '15 at 01:14
  • 1
    @PadraicCunningham Because I need to execute shell commands, not just start processes. I don't need to use shell=True specifically, but I need to use something that will allow me to run commands with sh or bash. – IGNUcius Apr 09 '15 at 01:22

0 Answers0