2

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

John Carter
  • 53,924
  • 26
  • 111
  • 144

2 Answers2

4

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.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
bashrc
  • 4,725
  • 1
  • 22
  • 49
1

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.

ConcernedOfTunbridgeWells
  • 64,444
  • 15
  • 143
  • 197
  • You still get a `SIGCHLD` when you separate, only it happens at the time the child separates, then the separated child has PID 1 as its parent so when that process dies, `SIGCHLD` is sent to process 1 (which more or less is the kernel) – Alexis Wilke Jun 25 '16 at 17:29