免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1685 | 回复: 0
打印 上一主题 下一主题

How to kill a zombie process in Linux? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-07 22:52 |只看该作者 |倒序浏览
When parent cannot handle the exited child process, the child process becomes a zombie, also known as a defunct process. The defunct process uses a little resource. It cannot be killed by kill(). It exists in all the system life. Then how to kill a zombie process? There are several ways to kill a zombie process or avoid to generate a zombie process as follows:
1. Kill the parent to eliminate the zombie processes
2. Wait a child to exit through calling wait() to avoid to generate a zombile process
3. Ignore the SIGCHLD signal (in Linux 2.6 but 2.4; POSIX-2001) to avoid to generate a zombie process
It should be noted that a zombie process is defunct so that any kill() or related command cannot affect it.
example 1: Call signal() to avoid to generate a zombie process
           The main process(parent process) is not blocked
...
signal(SIGCHLD, SIG_IGN);
...
if ((pid = fork()) == -1){
  ...
}
else if (!pid) {
  ...
  exit(0);
}
...
$kill -9 {CHILD}
$ps x
/* child not ba a zombie */
example 2: Call wait() to avoid to generate a zombie process
           The main process(parent process) is blocked
...
if ((pid = fork()) == -1){
  ...
}
else if (!pid) {
  ...
  exit(0);
}
wait(&child_exit_status);
...
$kill -9 {CHILD}
$ps x
/* child not ba a zombie */
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103132/showart_2047620.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP