开发者

Will a child process send SIGCHLD on abort()?

开发者 https://www.devze.com 2023-01-18 03:32 出处:网络
If an application does a fork() and the child dies with an abort() (due to failing an assert()), will the parent process receive a SI开发者_如何学GoGCHLD?

If an application does a fork() and the child dies with an abort() (due to failing an assert()), will the parent process receive a SI开发者_如何学GoGCHLD?

If it's relevant this is on Debian 4 (gcc version 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). Check its output on strace.(strace executable)

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.


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()). 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消