Content deleted Content added
m Bot: link syntax and minor changes |
|||
(8 intermediate revisions by 6 users not shown) | |||
Line 3:
{{C_Standard Library}}
In the [[C Standard Library]], '''signal processing''' defines how a program handles various [[Signal (computing)|signals]] while it executes. A signal can report some exceptional behavior within the program (
==Standard signals==
Line 11:
*<code>SIGABRT</code> – "abort", abnormal termination.
*<code>SIGFPE</code> – [[
*<code>SIGILL</code> – "illegal", invalid instruction.
*<code>SIGINT</code> – "interrupt", interactive attention request sent to the program.
*<code>SIGSEGV</code> – "[[segmentation violation
*<code>SIGTERM</code> – "terminate", termination request sent to the program.
Line 28:
A signal handler is a [[Function (computer science)|function]] which is called by the target environment when the corresponding signal occurs. The target environment suspends execution of the program until the signal handler returns or calls <code>longjmp()</code>.
Signal handlers can be set with <code>signal()</code> or <code>sigaction()</code>. The behavior of <code>signal()</code> has been changed multiple times across history and
If the signal reports an error within the program (and the signal is not asynchronous), the signal handler can terminate by calling <code>abort()</code>, <code>exit()</code>, or <code>longjmp()</code>.
Line 34:
==Functions==
{| class="wikitable
! Function
! Description
Line 54:
#include <stdio.h>
#include <stdlib.h>
volatile sig_atomic_t status = 0;
static void catch_function(int signo) {
status = signo;
puts("Interactive attention signal caught.");▼
}
Line 66 ⟶ 68:
}
puts("Raising the interactive attention signal.");
if (raise(SIGINT)
fputs("Error raising the signal.\n", stderr);
return EXIT_FAILURE;
}
▲ if (status == SIGINT) puts("Interactive attention signal caught.");
puts("Exiting.");
return EXIT_SUCCESS;
|