Question

Signals differ between implementation. There are some nice tables in APUE (Advanced Programming in the Unix Environment), such as "Figure 10.1 UNIX System signals" on page 292 of the 2nd edition.

So let's take the exemplary SIGWAITING. Signals appear in the documentation as int, but most implementations seem to use a #define instead of a const int.

However, does the standard stipulate anywhere that one can rely on signals being #defined? Or can I assume it based on the fact that, say, virtually every existing implementation uses #define. Or is this a bad assumption altogether?

The rationale is this: if I can rely on #define being used, I can use #ifdef to hide the more exotic signals from implementations that don't use it. For const int constant names I am not aware of a similar mechanism that would allow this compile time decision to be made.

Was it helpful?

Solution

See the POSIX (2008, 2013) specification for <signal.h>. In part, it says:

The <signal.h> header shall define the following macros that are used to refer to the signals that occur in the system. Signals defined here begin with the letters SIG followed by an uppercase letter. The macros shall expand to positive integer constant expressions with type int and distinct values. The value 0 is reserved for use as the null signal (see kill()). Additional implementation-defined signals may occur in the system.

The following signals shall be supported on all implementations…

and this is followed by a table of signal names. The version you link to is the 2004 edition of the standard, and it is not so explicit about the signal names being macros, but the later version codifies existing practice.

So, to be POSIX conformant, the signal names shall be #define'd.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top