阻塞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 ...
程序描述:典型的进程池服务程序,父进程捕获子进程终止(主要是异常终止),进行善后处理。 已经设置除SIGALRM以外的信号外中断的系统调用都能自动重启。 另外也测试过手工重启和BLOCK信号,同样出现问题,请大家帮忙分析一下。 环境: SUSE Linux Enterprise Server 9 gcc version 3.3.3 (SuSE Linux) 测试: 大量客户端并发请求处理,服务程序调度子进程处理,子进程模拟异常退出,服务进程进...
请教一下: 我一个进程C先生成两个子进程A,B,这两个子进程又分别生成两个子进程A1,A2,B1,B2 然后我在A,B子进程中设置捕捉sigchld的函数,当A1或A2退出时,A进程也退出了.不知道为什么 当我在进程C中设置捕捉sigchld的函数时就OK 了... 期待高人指点迷津
[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-...
#include
在命令行下,设置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! ...
关于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 ...
.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 ...
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的啊。
本帖最后由 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 ...