SIGCHLD Signal Processing

22,985

Solution 1

background and foreground are job control concepts, and are part of the the shell. They are applied to processes and do not affect which process spawned (exec-ed) another process.

A child process is the result of a fork()-exec() call. The child gets a parent pid of the process that executed the fork() call. This is the context of the SIGCHLD signal, the parent pid receives the SIGCHLD signal. It does not matter whether the child process is "foreground" or "background", only the ppid matters on exit of the process.

Solution 2

There's no such thing as foreground child. The term background process is used to simply refer that we are mainly dealing with the parent process (which may create a child processes to do a part its job). When a child process exits SIGCHLD is always sent to parent process. However, the parent process usually ignores it. If parent wants to deal with exit of child Or to do some action only after the exit of child, then it can use the wait() system call to get the status of child process.

Share:
22,985
darksky
Author by

darksky

C, C++, Linux, x86, Python Low latency systems Also: iOS (Objective-C, Cocoa Touch), Ruby, Ruby on Rails, Django, Flask, JavaScript, Java, Bash.

Updated on August 05, 2022

Comments

  • darksky
    darksky almost 2 years

    In Unix, when a child process in background terminates, it sends a SIGCHLD signal to the parent to inform it that it terminated.

    Does the same happen even if the process was in foreground? If so, this means the parent will just ignore it.

    Is this right? Or if it is in foreground, then no signal is sent at all?