Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

posix

glibc

Update: the whole problem was on a bad line, it was a syntax error in my c++ code.

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?

like image 457
peterh Avatar asked Sep 06 '15 20:09

peterh


People also ask

What is a POSIX signal?

The POSIX signal implementation ensures that if a process is already. handling a signal, other incoming signals are suspended until the. handler returns. However, if a signal SIGx is sent while a SIGx signal.

Which POSIX signal Cannot be caught?

Certain POSIX signals do not go through the condition handling steps described above: SIGKILL and SIGSTOP cannot be caught or ignored; they always take effect. SIGCONT immediately begins all stopped threads in a process if SIG_DFL is set.

What is the hangup signal in Linux?

Signals in Linux. The HUP signal is sent to a process when its controlling terminal is closed. It was originally designed to notify a serial line drop (HUP stands for "Hang Up"). In modern systems, this signal usually indicates the controlling pseudo or virtual terminal is closed.

What is man7 signal?

A process- directed signal is one that is targeted at (and thus pending for) the process as a whole. A signal may be process-directed because it was generated by the kernel for reasons other than a hardware exception, or because it was sent using kill(2) or sigqueue(3).


1 Answers

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

like image 153
Jens Munk Avatar answered Oct 06 '22 19:10

Jens Munk