简体   繁体   English

子进程会在abort()上发送SIGCHLD吗?

[英]Will a child process send SIGCHLD on abort()?

If an application does a fork() and the child dies with an abort() (due to failing an assert() ), will the parent process receive a SIGCHLD ? 如果应用程序执行fork()并且子进程死于abort() (由于assert()失败),那么父进程会收到SIGCHLD吗?

If it's relevant this is on Debian 4 (gcc version 4.1.2). 如果相关,则在Debian 4(gcc版本4.1.2)上。

If you want to check the same,write a sample code which forks a child and the child calls abort() (To raise the sigabrt signal). 如果要进行相同的检查,请编写一个示例代码,该代码将派生一个子代,该子代将调用abort()(引发sigabrt信号)。 Check its output on strace.(strace executable) 在strace上检查其输出。(strace可执行文件)

For the following code: 对于以下代码:

 #include<stdio.h>
 #include<unistd.h>
 int main()
    {
    pid_t pid;
    if(pid=fork()<0)
            {
            fprintf(stderr,"Error in forking");
            }
    else if(pid==0)
            {
            /*The child*/
            abort();
            }
    else {
            waitpid(pid,(int *)0,0);
            }
    return 0;
    }

I get this output: 我得到以下输出:

     --- SIGCHLD (Child exited) @ 0 (0) ---
     gettid()                                = 4226
     tgkill(4226, 4226, SIGABRT)             = 0
     --- SIGABRT (Aborted) @ 0 (0) ---
     +++ killed by SIGABRT +++

So the answer is yes, at least on Ubuntu distro. 因此答案是肯定的,至少在Ubuntu发行版上是这样。

You would expect the parent to get a SIGCHLD any time a child terminates unless the child has separated itself off from the parent (IIRC using setsid() or setpgrp()). 除非孩子将自己与父级分离(IIRC使用setsid()或setpgrp()),否则您希望在子级终止时父级都能获得SIGCHLD The main reason for a child doing this is if the child is starting a daemon process. 子进程执行此操作的主要原因是,该子进程是否正在启动守护进程。 See Here or Here for a deeper treatment of daemon processes. 请参阅此处此处以更深入地处理守护进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM