Reading up on signal(7) I can see that now: two, but once: three; signal numbers past 31 are reserved for use by the Real-time signal system and should not be used:

Real-time Signals

Linux supports real-time signals as originally defined in the POSIX.1b real-time extensions (and now included in POSIX.1-2001). The range of supported real-time signals is defined by the macros SIGRTMIN and SIGRTMAX. POSIX.1-2001 requires that an implementation support at least POSIX_RTSIG_MAX(8) real-time signals.

The Linux kernel supports a range of 32 different real-time signals, numbered 33 to 64. However, the glibc POSIX threads implementation internally uses two (for NPTL) or three (for LinuxThreads) real-time signals (see pthreads(7)), and adjusts the value of SIGRTMIN suitably (to 34 or 35). Because the range of available real-time signals varies according to the glibc threading implementation (and this variation can occur at run time according to the available kernel and glibc), and indeed the range of real-time signals varies across UNIX systems, programs should never refer to real-time signals using hard-coded numbers, but instead should always refer to real-time signals using the notation SIGRTMIN+n, and include suitable (run-time) checks that SIGRTMIN+n does not exceed SIGRTMAX.

So, how do I determine the value (in a C program that needs to set up signal handling for itself and any children) of SIGRTMIN when the program is running? I have looked through questions and answers here but they all seem to treat SIGRTMIN as if it was a #define SIGRTMIN 34 when the man page says that should not be done!

  • I would discuss these concerns with the author of any package you saw using hard coded constants instead of using the defined macros. – Rui F Ribeiro Feb 29 '16 at 8:28
  • Ah, so it is a MACRO with a run-time value is it? Not a compile constant! Right I'll take a deeper look and see where it is.... – SlySven Feb 29 '16 at 8:36
  • 1
    asm-generic/signal.h:#define SIGRTMIN 32 signal.h:extern int __libc_current_sigrtmin (void) __THROW; x86_64-linux-gnu/bits/signum.h:#define SIGRTMIN (__libc_current_sigrtmin ()) x86_64-linux-gnu/bits/signum.h:#define __SIGRTMIN 32 x86_64-linux-gnu/asm/signal.h:#define SIGRTMIN 32 – Rui F Ribeiro Feb 29 '16 at 8:41

Stupidly I had forgotten that things that are #defined are not constant unless they are written that way!

As @RuiFRibeiro points out in the /usr/include/architecture-specific/bits/signum.h include file at the bottom is the pair of MACROS that provides what is needed:

#define SIGUNUSED   31

#define _NSIG       65  /* Biggest signal number + 1  
                   (including real-time signals).  */

#define SIGRTMIN        (__libc_current_sigrtmin ())  
#define SIGRTMAX        (__libc_current_sigrtmax ())  

/* These are the hard limits of the kernel.  These values should not be
   used directly at user level.  */
#define __SIGRTMIN  32  
#define __SIGRTMAX  (_NSIG - 1)

So now I know how to prevent signal handlers from being attempted to be replaced for those reserved one - I suspect any attempt would be rejected anyway but for error reporting it is better to know what the limits are rather than to determine them from a suck it and see approach!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.