限制信号处理程序仅捕获来自定义它的特定文件的信号

发布于 2024-11-02 18:51:13 字数 561 浏览 1 评论 0原文

你好 我在一个文件中定义了一个信号处理程序,信号是从该文件生成的。我定义了一个“静态结构 sigaction”来定义非静态的信号处理程序。

我们知道使用“静态”我们还可以将范围限制到一个文件,因此使用这种技术我们可以限制信号处理程序仅捕获来自定义它的文件的信号吗?

我的“文件” - File1,它与其他文件 - File2 链接,File2 可以生成信号,该信号不应被 File1 处理程序捕获。那么,如果我将“static struct sigaction”放入 File1 中,我可以实现此目的吗?

enter code here
File1.c

static struct sigaction;
void sigHandler(int sig); // also a handler for SIG_NO but should catch signals generated for only File1.c (sig handler is non-static)

File2.c
kill(getpid(), SIG_NO)

File1.c and File2.c are linked together.

Hi
I have a signal handler defined in one file, from where the signal is generated. I have defined a "static struct sigaction" to define a signal handler which is non-static.

We know using "static" we can also put scope limitation to one single file, so using this technique can we restrict the signal handler to catch signals from only the file in which it is defined?

My "file" - File1, which is linked with other file - File2, File2 can generate signals, which should not be caught by File1 handler. So can i achieve this, if i put "static struct sigaction" in File1?

enter code here
File1.c

static struct sigaction;
void sigHandler(int sig); // also a handler for SIG_NO but should catch signals generated for only File1.c (sig handler is non-static)

File2.c
kill(getpid(), SIG_NO)

File1.c and File2.c are linked together.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日暮斜阳 2024-11-09 18:51:14

在哪里声明/定义处理程序并不重要。如果您安装了处理程序,它会处理进程接收到的该类型的所有信号。

因此,无论标识符的范围和链接如何,一旦安装了处理程序,它就会处理所有事情。

It really doesn't matter where you declare / define the handler. If you get to install the handler, it handles ALL the signals of that type received by the process.

So, no matter the scope and linkage of your identifiers, once you install the handler it handles everything.

如歌彻婉言 2024-11-09 18:51:14

你不能直接。

有关哪个特定文件生成给定代码段的信息不是可执行文件的一部分(调试信息除外,但内核不使用或解析这些信息)。

如果仅在某些情况下对信号进行操作,则需要在应用程序和信号处理程序中实现一些逻辑。

(或者重新考虑您的应用程序设计并实施两个单独的流程。)

You can't directly.

The information about what specific file generated a given segment of code is not part of the executable (except for debug information, but that is not used or parsed by the kernel).

You'll need to implement some logic in your application and in the signal handler if the signal is only to be acted upon in some situations.

(Or re-think your application design and implement two separate processes.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文