Search code examples
posixglibc

How to get the maximal signal number on a posix-compatible way?


On Linux I've found

#define _NSIG            64

in asm-generic/signal.h, but I think including that wouldn't be a really standard-compliant solution.

signal.h in the glibc uses this _NSIG definition, but it hides behind a complex structure of include-define-undef-ifdef and similar preprocessor commands, and it isn't a visible symbol after a simple #include <signal.h>.

I am simply looking for a way to find the maximal signum I can give to sigaction and similar signal handling api calls, including the realtime signals. Is it somehow possible?


Solution

  • The POSIX.1-2001 standard requires the definition of SIGRTMIN and SIGRTMAX. On linux they are defined using _NSIG.

    To be POSIX compliant, use the above definitions instead of directly using _NSIG

    #include <stdio.h>
    #include <signal.h>
    
    int main() {
      printf("%lu\n", SIGRTMAX);
      return 0;
    }
    

    This prints 64 on my system when compiled using gcc main.cpp