John Carter
John Carter

Reputation: 55271

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?

If it's relevant this is on Debian 4 (gcc version 4.1.2).

Upvotes: 2

Views: 2832

Answers (2)

bashrc
bashrc

Reputation: 4835

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.

Upvotes: 4

ConcernedOfTunbridgeWells
ConcernedOfTunbridgeWells

Reputation: 66622

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.

Upvotes: 1

Related Questions