简体   繁体   中英

Kill a created subprocess and all processes created by it

What I want? Create a script that starts and kill a communication protocol

What I have? I have a python script that opens a shell script, and this shell script initialize the protocol. When I kill the parent process, everything goes fine (but in the final project, the parent process will have to stay alive), but when I kill the subprocess, it become a zombie function, and my protocol keep running.

Problems I believe can be: I'm "killing" the shell script (not the protocol, that's what I want)

The line I start the shell script:

`protocolProcess = subprocess.Popen(["sh", arquivo], cwd = localDoArquivo) #inicia o protocolo`

protocolProcessPID = protocolProcess.pid #armazena o pid do protocolProcess

The line I kill the shell script: os.kill(protocolPID, signal.SIGTERM)

Well, that's it! If anyone can help me, I'll be very grateful

Zombie processes are processes that have not yet been reaped by the parent process.

The parent process will hold onto those process handlers until the end of time, or until it reads the process exit status, or itself is killed.

It sounds like the parent process needs to have a better handle on how it spawns and reaps it's children. Simply killing a child process is not enough to free a zombie process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM