Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Linux signal: process exit if there's no handler

I’m using signal to transmit messages within my program, I write code like this:

union sigval sv;
sv.sival_ptr = (void*) data;
pid_t pid = getpid();
if (sigqueue(pid, SIGUSR2, sv) != 0) {
    Log("failed: %d", errno);
    return 0;
} else {
    // do something
}

And I found that if I don’t register a handler, my program will exit when calling sigqueue, as if I send a signal with SIGTERM, but im my code I send SIGUSR2. I checked the doc and nothing talks about the exit, so what did I do wrong?

P.S. The program might not register the handler by design.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I checked the doc and nothing talks about the exit, so what did I do wrong?

You simply did not find the right documentation 🙂

From man 7 signal you will get a list of signals and the default behavior, if no handler was set by user.

Stolen form the man page:

DESCRIPTION
       Linux  supports both POSIX reliable signals (hereinafter "standard sig-
       nals") and POSIX real-time signals.

   Signal dispositions
       Each signal has a current disposition, which determines how the process
       behaves when it is delivered the signal.

       The  entries  in the "Action" column of the table below specify the de-
       fault disposition for each signal, as follows:

       Term   Default action is to terminate the process.

       Ign    Default action is to ignore the signal.

       Core   Default action is to terminate the process and  dump  core  (see
              core(5)).

       Stop   Default action is to stop the process.

       Cont   Default  action  is  to  continue the process if it is currently
              stopped.

And from the table of default actions:

      Signal      Standard   Action   Comment
      ------------------------------------------------------------------------
 
       SIGABRT      P1990      Core    Abort signal from abort(3)
...
       SIGUSR1      P1990      Term    User-defined signal 1
       SIGUSR2      P1990      Term    User-defined signal 2

As you can see, if no other action was specified by user, the program terminates if it receives a SIGUSR1 or SIGUSR2.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading