views:

111

answers:

2

If I setup sighandler and then do a fork. Will the child process also inherit the sighandlers?

+2  A: 

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.

So, while the pending signals do not make it through the fork() operation, the signal handlers themselves do. This makes sense since the signals belong to the (parent) process.

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
A: 

Yes fork() divides the process into two. All the resources that are applicable to parent process are available to child process too.

Sachin Chourasiya