2

我想在 perl 中编写一个强大的守护程序,它将在 Linux 上运行,并遵循这个出色答案中描述的模板。但是我的情况有一些不同:首先我使用的是Parallel::ForkManager start() and next;派生一个事件,紧随其后exec('handle_event.pl')

在这种情况下,我有以下问题:

  1. 我应该在哪里定义我的信号处理程序。我应该在父级(守护进程)中定义它们并假设它们将在子级中继承吗?
  2. 如果我运行exec('handle_event.pl'),处理程序是否会跨 exec 继承(我知道它们是跨 exec 继承的fork)?
  3. 如果我重新定义一个新的信号处理程序,handle_event.pl这个定义会覆盖父级中定义的那个吗?
  4. 在这种情况下,最佳实践是什么?

谢谢

4

2 回答 2

5

When you fork, the child process has the same signal handlers as the parent. When you exec, any ignored signals remain ignored; any handled signals are reset back to the default handler.

于 2009-12-22T08:22:49.537 回答
4

The exec replaces the whole process code with the code that will be executed. As signal handlers are code in the process image, they cannot be inherited across an exec, so exec will reset the signal handling dispositions of handled signals to their default states (ignored signals will remain ignored). You will therefore need to install any signal handling in the execed process when it starts up.

于 2009-12-22T08:13:07.140 回答