有没有办法在 Linux 中创建用户定义的信号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5741604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to create a user defined signal in Linux?
提问by kingsmasher1
Is there any way to create a user defined signals in Linux? My signal (signal number) should not match any of the existing signal numbers.
有没有办法在 Linux 中创建用户定义的信号?我的信号(信号编号)不应与任何现有信号编号匹配。
In other words, i want to create my own unique signal, which will be registered and caught by my handler.
换句话说,我想创建我自己独特的信号,它将被我的处理程序注册和捕获。
Is it possible? If yes, how?
是否可以?如果是,如何?
Thanks in advance.
提前致谢。
采纳答案by adobriyan
You can't add or register your own SIGWHATEVER.
您不能添加或注册自己的 SIGWHATEVER。
See sigset_t
, it is fixed size. See valid_signal()
beartraps.
看sigset_t
,它是固定大小的。见valid_signal()
捕熊器。
回答by Didier Trosset
There are the USR1
and USR2
signals designed for user defined purposes.
有为用户定义的目的而设计的USR1
和USR2
信号。
回答by Noufal Ibrahim
You can use USR1 and USR2 for this kind of thing.
您可以将 USR1 和 USR2 用于此类事情。
If that's not enough, you can emulate signal like behaviour by having your application listen on a socket which external apps can send messages to.
如果这还不够,您可以通过让您的应用程序侦听外部应用程序可以向其发送消息的套接字来模拟类似信号的行为。
回答by Florian
You can compile your own kernel with special signals :)
您可以使用特殊信号编译自己的内核:)
回答by R.. GitHub STOP HELPING ICE
SIGRTMIN
through SIGRTMAX
(these are not normally constants but macros which expand to functions evaluated at runtime) are available for whatever use you like, as are SIGUSR1
and SIGUSR2
. The former have additional realtime queueing support; the latter don't. Simply choose one to use.
SIGRTMIN
通过SIGRTMAX
(这些通常不是常量,而是扩展为在运行时评估的函数的宏)可用于您喜欢的任何用途,就像SIGUSR1
和 一样SIGUSR2
。前者有额外的实时排队支持;后者没有。只需选择一种即可使用。