behavior of parent and child for a signal handler

我的未来我决定 提交于 2021-02-17 21:39:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!