C signal handling: Difference between revisions

Content deleted Content added
Handling: grammar fix
FrescoBot (talk | contribs)
m Bot: link syntax and minor changes
 
(6 intermediate revisions by 5 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 (''such as [[division by zero]]''), or a signal can report some asynchronous event outside the program (''such as someone striking an [[SIGINT (POSIX)|interactive attention key]] on a keyboard'').
 
==Standard signals==
Line 11:
 
*<code>SIGABRT</code> – "abort", abnormal termination.
*<code>SIGFPE</code> – [[Floatingfloating point exception|'''f'''loating '''p'''oint '''e'''xception]].
*<code>SIGILL</code> – "illegal", invalid instruction.
*<code>SIGINT</code> – "interrupt", interactive attention request sent to the program.
*<code>SIGSEGV</code> – "[[segmentation violation|'''seg'''mentation '''v'''iolation]]", invalid memory access.
*<code>SIGTERM</code> – "terminate", termination request sent to the program.
 
Line 34:
==Functions==
 
{| class="wikitable" style="font-size:0.85em"
! 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) != 0) {
fputs("Error raising the signal.\n", stderr);
return EXIT_FAILURE;
}
if (status == SIGINT) puts("Interactive attention signal caught.");
puts("Exiting.");
return EXIT_SUCCESS;