SIGCHLD信号没有屏蔽,为什么??

建树 2009-08-28 05:30:59
#include<stdio.h>
#include<sys/types.h>
#include<signal.h>
void *sigMyFuc()
{
printf("signal is send\n");
return;
}
int main(int argc,char*argv[])
{

pid_t pid;
char buf[20];
struct sigaction Sig;
sigemptyset(&Sig.sa_mask);
sigaddset(&Sig.sa_mask,SIGCHLD);
Sig.sa_flags=0;
Sig.sa_handler=sigMyFuc;
sigaction(SIGCHLD,&Sig,&Sig);

pid=fork();
if(pid<0)
{
printf("fork error\n");
return -1;
}
else if(pid==0)
{
sprintf(buf,"%d\n",pid);

}
else
{
waitpid(pid,NULL,0);
sprintf(buf,"%d\n",pid);

}
exit(0);
}



在上面的程序中我在sigaction函数中屏蔽了SIGCHLD信号,但当子进程退出时,父进程还是相应了,这是为什么???
还有就是sa_flags=0;代表的是什么意思??
...全文
217 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mymtom 2009-08-28
  • 打赏
  • 举报
回复
sa_mask的意思是在执行信号处理函数(handler)的时候还需要阻塞的信号。

http://www.opengroup.org/onlinepubs/009695399/functions/sigaction.html

sa_mask: Additional set of signals to be blocked during execution of signal-catching function.

关于sa_flags:

The following flags, defined in the header <signal.h>, can be set in sa_flags:

SA_NOCLDSTOP
Do not generate SIGCHLD when children stop.
ot generate SIGCHLD when children stop.
SA_ONSTACK
If set and an alternate signal stack has been declared with sigaltstack() or sigstack(), the signal will be delivered to the calling process on that stack. Otherwise, the signal will be delivered on the current stack.
SA_RESETHAND
If set, the disposition of the signal will be reset to SIG_DFL and the SA_SIGINFO flag will be cleared on entry to the signal handler.

Note:
SIGILL and SIGTRAP cannot be automatically reset when delivered; the system silently enforces this restriction.

Otherwise, the disposition of the signal will not be modified on entry to the signal handler.

In addition, if this flag is set, sigaction() behaves as if the SA_NODEFER flag were also set.

SA_RESTART
This flag affects the behaviour of interruptible functions; that is, those specified to fail with errno set to [EINTR]. If set, and a function specified as interruptible is interrupted by this signal, the function will restart and will not fail with [EINTR] unless otherwise specified. If the flag is not set, interruptible functions interrupted by this signal will fail with errno set to [EINTR].

SA_SIGINFO
If cleared and the signal is caught, the signal-catching function will be entered as:


void func(int signo);

where signo is the only argument to the signal catching function. In this case the sa_handler member must be used to describe the signal catching function and the application must not modify the sa_sigaction member.
lzy0001sl 2009-08-28
  • 打赏
  • 举报
回复
signal(SIGCHLD, SIG_IGN);
lwh_1024 2009-08-28
  • 打赏
  • 举报
回复
忽略信号好像是这个函数吧:signal

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧