ChinaUnix.net
相关文章推荐:

SIGCHLD 信号量

进程一章讲过用wait和waitpid函数清理僵尸进程,父进程可以阻塞等待子进程结束,也可以非阻塞地查询是否有子进程结束等待清理(也就是轮询的方式)。采用第一种方式,父进程阻塞了就不能处理自己的工作了;采用第二种方式,父进程在处理自己的工作的同时还要记得时不时地轮询一下,程序实现复杂。 其实,子进程在终止时会给父进程发sigchld信号,该信号的默认处理动作是忽略,父进程可以自定义sigchld信号的处理函数,这样父...

by c08007 - Linux文档专区 - 2009-05-31 15:37:47 阅读(898) 回复(0)

相关讨论

阻塞sigchld信号 我在看APUE的10.18节——system函数和在分析linux的/sbin/init程序的源代码时遇到了一个相同的、让我迷惑了好一阵的问题,相关的代码如下: 代码1:APUE10.18节的system函数源代码 int system(const char *cmdstring) /* with appropriate signal handling */ { pid_t pid; int status; struct sigaction ignore, saveintr, savequit; sigset_t ...

by hackbutter - Linux文档专区 - 2008-02-29 11:29:40 阅读(1483) 回复(0)

程序描述:典型的进程池服务程序,父进程捕获子进程终止(主要是异常终止),进行善后处理。 已经设置除SIGALRM以外的信号外中断的系统调用都能自动重启。 另外也测试过手工重启和BLOCK信号,同样出现问题,请大家帮忙分析一下。 环境: SUSE Linux Enterprise Server 9 gcc version 3.3.3 (SuSE Linux) 测试: 大量客户端并发请求处理,服务程序调度子进程处理,子进程模拟异常退出,服务进程进...

by wjianc - C/C++ - 2007-08-21 16:48:15 阅读(5842) 回复(2)

请教一下: 我一个进程C先生成两个子进程A,B,这两个子进程又分别生成两个子进程A1,A2,B1,B2 然后我在A,B子进程中设置捕捉sigchld的函数,当A1或A2退出时,A进程也退出了.不知道为什么 当我在进程C中设置捕捉sigchld的函数时就OK 了... 期待高人指点迷津

FORKSIGCHLD

by wolf711988 - C/C++ - 2010-04-24 22:25:25 阅读(1774) 回复(2)

[code]int main() { // signal handle struct sigaction sigchld; sigchld.sa_handler = sig_chld_action; sigaction(sigchld, &sigchld, 0); // make several child-proc .......... for ( ; ; ) // parent pause(); } void sig_chld_action(int signo) { pid_t pid; while ( (pid = waitpid(-1, NULL, WNOHANG)) > 0 ) ; return ; }[/code]命令行kill child-pid,本意是只终止child-...

by bingdong2013 - C/C++ - 2013-05-15 17:45:30 阅读(1320) 回复(2)

#include #include #include #include #include void sig_child(int signo) { int status,res; if((waitpid(-1,&status,WNOHANG))<0) { perror("wait"); exit(1); } else { printf("process exit status %d\n",WEXITSTATUS(status)); } // printf("child has finished\n"); } int main() { pid_t pid; pid=fork(); if(pid<...

by libing741799085 - Linux环境编程 - 2012-06-04 10:25:25 阅读(2508) 回复(5)

在命令行下,设置sigchld信号捕获. [root@localhost ~]# trap 'echo Catch sigchld ok!' sigchld #在当前shell设置sigchld信号 [root@localhost ~]# pwd #bash内部命令不产生子进程 /root [root@localhost ~]# (pwd) #让pwd在子进程中运行 /root Catch sigchld ok! #子进程结束,捕获到sigchld信号 [root@localhost ~]# hostname #外部命令产生子进程 localhost.localdomain Catch sigchld ok! ...

by kvkingdom - Shell - 2009-04-09 14:42:16 阅读(2062) 回复(2)

关于SIG_CHLD信号传递机制,从内核角度做些分析: 1.child退出,调用do_exit() do_exit()->exit_notify->do_notify_parent if (!tsk->ptrace && sig == sigchld && (psig->action[sigchld-1].sa.sa_handler == SIG_IGN || (psig->action[sigchld-1].sa.sa_flags & SA_NOCLDWAIT))) { /* * We are exiting and our parent doesn't care. POSIX.1 * defines special semantics ...

by kinwin - Linux文档专区 - 2008-10-23 14:58:46 阅读(607) 回复(0)

.tt1 {font-size: 10pt;} 5.9 Handling sigchld Signals The purpose of the zombie state is to maintain information about the child for the parent to fetch at some later time. This information includes the process ID of the child, its termination status, and information on the resource utilization of the child (CPU time, memory, etc.). If a process terminates, and that process has children in ...

by wangxiaofeng - Linux文档专区 - 2008-08-01 17:54:27 阅读(1149) 回复(0)

APUE上这么说 Whenever a process terminates or stops, the sigchld signal is sent to the parent. 首先我不知道terminate和stop有什么不同 system(cmd)通过fork一个进程执行/bin/sh -c cmd,/bin/sh是不是要等到cmd返回以后才返回? 而system又要等要/bin/sh返回后再返回? 如果是这样,system为什么要阻塞sigchld呢?因为cmd结束时sigchld的发送给/bin/sh的啊。

by jronald - C/C++ - 2006-11-26 19:49:53 阅读(1853) 回复(5)

本帖最后由 embeddedlwp 于 2012-04-23 17:34 编辑 linux 2.6.11中worker_thread被调用的流程如下: create_workqueue->__create_workqueue->create_workqueue_thread->kthread_create->worker_thread: worker_thread其中有这么一段:[code] /* Block and flush all signals */ 194 sigfillset(&blocked); 195 sigprocmask(SIG_BLOCK, &blocked, NULL); 196 flush_signals(current); 197 198 ...

by embeddedlwp - 内核源码 - 2012-05-02 16:12:09 阅读(2042) 回复(6)