CKTIS / C
raise — raise a signal
raise(sig) triggers signal handling according to the current setting; it does not register a handler.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <signal.h>
int raise(int sig);raise(sig) from <signal.h> raises a signal. signal selects the response: a handler, SIG_IGN (ignore), or SIG_DFL (implementation-defined default behavior).
The result is 0 on success, nonzero on failure. If a handler is called and returns, raise returns only afterward; program termination can prevent a return.
Under N3096, a handler invoked by raise must not call raise. Returning from a handler for SIGFPE, SIGILL, or SIGSEGV causes undefined behavior. Using signal in a multithreaded program is also undefined.
The example uses SIGTERM; its handler only assigns to volatile sig_atomic_t. Printing happens afterward.
Examples
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static volatile sig_atomic_t received = 0;
static void handle_signal(int sig)
{
(void)sig;
received = 1;
}
int main(void)
{
if (signal(SIGTERM, handle_signal) == SIG_ERR) {
return EXIT_FAILURE;
}
if (raise(SIGTERM) != 0) {
return EXIT_FAILURE;
}
if (received == 0) {
return EXIT_FAILURE;
}
puts("Signal handled");
return EXIT_SUCCESS;
}Result
Signal handled
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.