Killing a process leaves zombie process to haunt me... :(
I have a program wherein i use fork. In the child process, i just login to a remote server and executes a command. In the parent process, i wait for the child to finish its task. If it doesnot finish it in a predetermined amount of time, i kill the child process using kill(child_pid, SIGTERM). But i have noticed that this leaves behind zombie process like
93113 s000 开发者_开发知识库 Z+ 0:00.00 (ssh)
and as the timeouts increase, the zombie process also increase and ultimately the ssh cannot be used anymore.
how can i kill the child process without creating zombies that haunt me??
Even if you kill
the child, you still need to wait
for it.
You must listen for SIGCHLD
in the parent process and get the exit code of the child using wait()
et al.
精彩评论