erbal
erbal

Reputation: 727

How to kill a child process

I've found several methods to kill a child process. I would like to use the os.kill(pid). But it doesn't work, I guess it should though.

def onExit():
    os.kill(logProc, 0)
    QtCore.QCoreApplication.instance().quit
    return

button.clicked.connect(onExit)

logProc=os.fork()
if logProc>0:
    proc()

Upvotes: 4

Views: 3198

Answers (1)

falsetru
falsetru

Reputation: 369444

You should pass signals like signal.SIGKILL (9), signal.SIGTERM (15) to kill the process.

import signal

...

os.kill(logProc, signal.SIGKILL)

According to Linux kill(2):

If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID orprocess group ID.

Upvotes: 4

Related Questions