问题
A process has a 'fork' call after a signal handler has been registered [for SIGINT]. what happens when SIGINT is sent through command line ? whether parent gets exited or child or both ? parent and child both are running infinite while loops.
回答1:
If you do fork
(without further exec*
) after a signal handler has been registered, the same signal handler will be used in parent and child processes. That is, if you do something other than exit
in your SIGINT
handler, neither parent nor child will exit (how SIGINT
was sent is irrelevant here).
If you mean a SIGINT
sent from the terminal (by vintr
character which is usually Ctrl+C
): it will be received by processes using the terminal as controlling terminal. That is, unless you detach child or parent from controlling terminal, both will react to Ctrl+C
by calling your SIGINT
handler.
来源:https://stackoverflow.com/questions/14852587/behavior-of-parent-and-child-for-a-signal-handler