LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1108|回复: 6

SIGKILL信号总是产生zombie进程,该怎样避免?

[复制链接]
发表于 2006-2-16 11:26:32 | 显示全部楼层 |阅读模式
编写的程序用了SIGKILL信号,但总是产生zombie进程。设置:
struct sigaction act;
act.sa_handler = SIG_IGN;
sigemptyset (&act.sa_mask);
act.sa_flags = SA_NOCLDWAIT;         
sigaction (SIGCHLD, &act, NULL);
只能消除其它信号产生的zombie进程,对SIGKILL产生的zombie进程也无济于事。
发表于 2006-2-16 11:39:59 | 显示全部楼层
zombie一定要wait的
为SIGCHLD注册一个handler
  1. void sigchld_handler(int s){
  2.        while(waitpid(-1, NULL, WNOHANG) > 0);
  3. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-2-16 12:42:27 | 显示全部楼层
直接注册成SIG_IGN就行了
回复 支持 反对

使用道具 举报

发表于 2006-2-16 12:44:47 | 显示全部楼层
SIGKILL 信号可以被忽略吗?

参看 signal(7)
回复 支持 反对

使用道具 举报

发表于 2006-2-16 12:52:29 | 显示全部楼层
是父进程将SIGCHLD注册成SIG_IGN
回复 支持 反对

使用道具 举报

发表于 2006-2-16 12:58:52 | 显示全部楼层
from man sigaction
POSIX.1-1990  disallowed setting the action for SIGCHLD to SIG_IGN.  POSIX.1-2001 allows this pos-
       sibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies  (see  wait(2)).
       Nevertheless,  the historical BSD and System V behaviours for ignoring SIGCHLD differ, so that the
       only completely portable method of ensuring that terminated children do not become zombies  is  to
       catch the SIGCHLD signal and perform a wait(2) or similar.
回复 支持 反对

使用道具 举报

发表于 2006-2-16 13:16:20 | 显示全部楼层
thanks
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表