user3475234
user3475234

Reputation: 1573

C- what exactly is SIGUSR1 syntactically

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

Upvotes: 16

Views: 30675

Answers (2)

phoxis
phoxis

Reputation: 61970

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.

Upvotes: 21

BadZen
BadZen

Reputation: 4274

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.

Upvotes: 8

Related Questions