How to kill a child process

浪尽此生 提交于 2021-02-08 23:42:13

问题


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()

回答1:


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.



来源:https://stackoverflow.com/questions/20259873/how-to-kill-a-child-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!