C- what exactly is SIGUSR1 syntactically

时间秒杀一切 提交于 2019-12-23 08:59:13

问题


When I use SIGUSR1 in the kill() or signal() functions, what is it doing? Is it a macro? I read that it was user defined, but where is it defined? Can I make a SIGUSR10 (or programatically make an "array" of different signal types)?


回答1:


User defined signals means that these signals have no definite meaning unlike SIGSEGV, SIGCONT, SIGSTOP, etc. The kernel will never send SIGUSR1 or SIGUSR2 to a process, so the meaning of the signal can be set by you as per the needs of your application. All these uppercase SIG constants are actually macros which will expand to an integer indicating a signal number in the particular implementation. Although user defined signals do not necessarily need to be defined, the signal numbers are already fixed in a particular implementation, and they can be safely re-purposed since they will not be sent by anything except for the user.

Traditionally, there have been two user-defined signals: SIGUSR1 and SIGUSR2. However, recent implementations have something called "POSIX realtime signals" which offer several more user-defined signals.




回答2:


SIGUSR is, as the name implies, a signal reserved for use by the user (developer), without any "special" pre-defined meaning. You can't make 10 of them, on most POSIX systems there are exactly two - SIGUSR1 and SIGUSR2.

The symbol itself may or may not be a macro expansion, but will end up being a numeric value assignment-compatible with int.

To use it in a meaningful way, you will need to write a signal handler. See the signal() manpage for details on how to do this.



来源:https://stackoverflow.com/questions/25736623/c-what-exactly-is-sigusr1-syntactically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!