tags:

views:

32

answers:

1
+1  Q: 

Signals in fork

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

+4  A: 

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

paxdiablo