信号处理程序是否有可能在“ exec”之后生存?
我为一个过程写了一个信号处理程序,然后fork()之后,信号处理程序将应用于父母和子过程。如果我用“ exec”替换子过程,则信号处理程序已不复存在。
我知道发生这种情况是因为“执行”呼叫将用自己的呼叫覆盖子过程地址空间。 我只想知道即使在“执行”呼叫之后,是否有一种方法可以使信号处理程序工作?
I wrote a signal handler for a process, and fork() after that, the signal handler will be applied to both parent and child processes. If I replace the child process with "exec", the signal handler is no more.
I know this happens because "exec" call will overwrite the child process address space with it's own.
I just want to know if there is a way to make signal handler work even after "exec" call ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否。从
man
页面:实际上,如果信号处理程序在代码被一些非常不同的代码替换后仍处于活动状态,则您可能会期望在信号发生时各种混乱。毕竟,信号处理程序是发生某些事情时要调用的地址(折扣
sig_ign
和sig_dfl
暂时)。当您替换整个文本段时,谁知道该地址的代码会在该地址上是什么?No. From the
man
pages:In fact, if the signal handler were still active after the code had been replaced with some very different code, you could expect all sorts of mayhem when the signal occurred. The signal handler is, after all, just an address to call when something happens (discounting
SIG_IGN
andSIG_DFL
for now). Who knows what piece of code would be at that address when you replace the entire text segment?