Chinaunix

标题: AIX4.3,已忽略SIGCHLD,但还是会有僵尸 [打印本页]

作者: littlezgj    时间: 2007-12-28 02:36
标题: AIX4.3,已忽略SIGCHLD,但还是会有僵尸
AIX4.3,
一守护进程,一直循环等待从消息队列中取消息,来一个消息fork一个进程,
消息量大时会产生僵尸进程(defunct),但已忽略SIGCHLD信号(sigaction),
僵尸进程隔1、2s僵尸自动会消失

我的主进程没有推出,这个僵尸也会自动消失
按照僵尸的说法,僵尸一直会等主进程退出才会消失,但是我的没有退出也会消失,为什么呢?
难道跟AIX4.3系统的实现有关??

谢谢。
作者: flw2    时间: 2007-12-28 09:11
你的父进程来不及wait?
作者: converse    时间: 2007-12-28 09:27
不存在忽略该信号就不会产生僵尸的说法.要不产生僵尸,只有父进程wait子进程退出才行.
作者: caijimin    时间: 2007-12-28 10:59
原帖由 converse 于 2007-12-28 09:27 发表
不存在忽略该信号就不会产生僵尸的说法.要不产生僵尸,只有父进程wait子进程退出才行.

真的吗?如果父进程就是不想管子进程是否退出,只管生不管收尸,忽略掉SIGCHLD没用,必须调用wait?
作者: converse    时间: 2007-12-28 11:02
标题: 回复 #4 caijimin 的帖子
有的父进程产生了子进程之后就一直在wait子进程退出,什么事情都不做;有的父进程还要去做别的事情,SIGCHLD就用于异步通知这样的父进程,在接收到这个信号之后在处理函数中调用wait让子进程退出,完事了父进程继续做自己的事情去.

但是,唯有父进程wait子进程退出了才不会产生僵尸.
作者: littlezgj    时间: 2007-12-28 11:23
也就是说忽略SIGCHLD并不能保证不会产生zombie,只能用wait了

还得在主进程中进行信号阻塞

谢谢了
作者: jameszxj    时间: 2007-12-28 11:47
unp上建议用waitpid最好
作者: caijimin    时间: 2007-12-28 12:35
我在FreeBSD 5.4上 man signal

     If a process explicitly specifies SIG_IGN as the action for the signal
     SIGCHLD, the system will not create zombie processes when children of the
     calling process exit.  As a consequence, the system will discard the exit
     status from the child processes.  If the calling process subsequently
     issues a call to wait(2) or equivalent, it will block until all of the
     calling process's children terminate, and then return a value of -1 with
     errno set to ECHILD.
作者: converse    时间: 2007-12-28 12:53
标题: 回复 #8 caijimin 的帖子
我在linux上同样看了man signal,上面是这么写的:

According  to  POSIX  (3.3.1.3)  it  is  unspecified  what happens when
       SIGCHLD is set to SIG_IGN.  Here the BSD and  SYSV  behaviours  differ,
       causing  BSD  software  that  sets the action for SIGCHLD to SIG_IGN to
       fail on Linux.


APUE2中是这么写的:
SIGCHLD
Whenever a process terminates or stops, the SIGCHLD signal is sent to the parent. By default, this signal is ignored, so the parent must catch this signal if it wants to be notified whenever a child's status changes. The normal action in the signal-catching function is to call one of the wait functions to fetch the child's process ID and termination status.


而关于僵尸进程APUE2是这么写的(section8.5):
In UNIX System terminology, a process that has terminated, but whose parent has not yet waited for it, is called a zombie.

作者: G00GLE    时间: 2007-12-28 12:56
APUE上说,默认对SIGCHLD的动作是SIG_IGN, 那样和你调用signal或sigaction来设置这个信号的忽略操作有什么区别呢,所以不wait子进程的话,僵尸进程还是会产生的吧,也许不同平台有不同的实现,还请大家指教。

比较同意2楼的说法,也许是wait忙不过来
作者: caijimin    时间: 2007-12-28 14:57
原帖由 converse 于 2007-12-28 12:53 发表
我在linux上同样看了man signal,上面是这么写的:



APUE2中是这么写的:


而关于僵尸进程APUE2是这么写的(section8.5):

谢谢converse详细和耐心的解释!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2