Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signals in fork

Tags:

fork

unix

signals

What is signal behavior in the fork. Should all signals are inherited in fork If not then which one and why?

like image 740
CrazyC Avatar asked Jul 12 '10 09:07

CrazyC


People also ask

Is fork signal safe?

POSIX specifies that fork can be called safely from signal handlers; it is required to be an async-signal-safe function.

How many signals are there in Linux?

There are 31 standard signals, numbered 1-31. Each signal is named as " SIG " followed by a suffix. Starting from version 2.2, the Linux kernel supports 33 different real-time signals.

What is a Sigchld signal?

The SIGCHLD signal is the only signal that the z/TPF system sends to a process. When a child process created by the tpf_fork function ends, the z/TPF system: Sends a SIGCHLD signal to the parent process to indicate that the child process has ended.

What gives signal to kernel?

The common communication channel between user space program and kernel is given by the system calls.


1 Answers

At least under Linux, signal handlers themselves are inherited but not the pending signals.

Quoting the Linux fork(2) man page:

fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.

This makes sense since the signals belong to the (parent) process. The newly created process is (mostly) a copy of the current process so signal handlers are preserved.

Although not directly related, the exec()-type call that often follows a fork() will destroy all signal handlers since a brand new executable is being loaded into the process (overwriting the functions currently servicing signals).

like image 142
paxdiablo Avatar answered Sep 21 '22 15:09

paxdiablo