6

I have damon in python which runs external program:

subprocess.call(["java", "-jar", "start.jar"])

when I kill daemon, the child process (java) is still running

how can I make so that child process is also killed ?

1
  • How are you killing the daemon? If you use kill -9, there's nothing you can do, but otherwise you could probably write a signal handler for that signal, catch it to kill the java process, and then exit gracefully. Commented Feb 25, 2011 at 8:09

1 Answer 1

9

Use subprocess.Popen() instead of subprocess.call(). For example:

import subprocess
my_process = subprocess.Popen(['ls', '-l'])

To terminate the child:

my_process.kill()

To capture the kill signal, you could so something like this:

import signal
import sys
def signal_handler(signal, frame):
    sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.