开发者

Restricting a signal handler to catch signals from only that particular file where it is defined

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.


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.


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜