[英]Killing a process leaves zombie process to haunt me… :(
I have a program wherein i use fork. 我有一个使用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).
如果它没有在预定的时间内完成,则使用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. 随着超时的增加,僵尸进程也增加,最终无法再使用ssh。
how can i kill the child process without creating zombies that haunt me?? 我如何杀死子进程而不会造成困扰我的僵尸?
即使kill
孩子,您仍然需要wait
。
您必须在父进程中监听SIGCHLD
,并使用wait()
等获取子进程的退出代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.