免费注册 查看新帖 |

Chinaunix

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

AIX4.3,已忽略SIGCHLD,但还是会有僵尸 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-28 02:36 |只看该作者 |倒序浏览
AIX4.3,
一守护进程,一直循环等待从消息队列中取消息,来一个消息fork一个进程,
消息量大时会产生僵尸进程(defunct),但已忽略SIGCHLD信号(sigaction),
僵尸进程隔1、2s僵尸自动会消失

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

谢谢。

论坛徽章:
0
2 [报告]
发表于 2007-12-28 09:11 |只看该作者
你的父进程来不及wait?

论坛徽章:
0
3 [报告]
发表于 2007-12-28 09:27 |只看该作者
不存在忽略该信号就不会产生僵尸的说法.要不产生僵尸,只有父进程wait子进程退出才行.

论坛徽章:
0
4 [报告]
发表于 2007-12-28 10:59 |只看该作者
原帖由 converse 于 2007-12-28 09:27 发表
不存在忽略该信号就不会产生僵尸的说法.要不产生僵尸,只有父进程wait子进程退出才行.

真的吗?如果父进程就是不想管子进程是否退出,只管生不管收尸,忽略掉SIGCHLD没用,必须调用wait?

论坛徽章:
0
5 [报告]
发表于 2007-12-28 11:02 |只看该作者

回复 #4 caijimin 的帖子

有的父进程产生了子进程之后就一直在wait子进程退出,什么事情都不做;有的父进程还要去做别的事情,SIGCHLD就用于异步通知这样的父进程,在接收到这个信号之后在处理函数中调用wait让子进程退出,完事了父进程继续做自己的事情去.

但是,唯有父进程wait子进程退出了才不会产生僵尸.

论坛徽章:
0
6 [报告]
发表于 2007-12-28 11:23 |只看该作者
也就是说忽略SIGCHLD并不能保证不会产生zombie,只能用wait了

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

谢谢了

论坛徽章:
0
7 [报告]
发表于 2007-12-28 11:47 |只看该作者
unp上建议用waitpid最好

论坛徽章:
0
8 [报告]
发表于 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.

论坛徽章:
0
9 [报告]
发表于 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.

论坛徽章:
0
10 [报告]
发表于 2007-12-28 12:56 |只看该作者
APUE上说,默认对SIGCHLD的动作是SIG_IGN, 那样和你调用signal或sigaction来设置这个信号的忽略操作有什么区别呢,所以不wait子进程的话,僵尸进程还是会产生的吧,也许不同平台有不同的实现,还请大家指教。

比较同意2楼的说法,也许是wait忙不过来
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP