Namespaces
Variants

std::raise

From cppreference.com
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)    
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
Defined in header <csignal>
int raise( int sig );

Sends signal sig to the program. The signal handler (specified using the std::signal() function) is invoked.

If the user-defined signal handling strategy is not set using std::signal() yet, it is implementation-defined whether the signal will be ignored or default handler will be invoked.

Parameters

sig - the signal to be sent. It can be an implementation-defined value or one of the following values:
defines signal types
(macro constant) [edit]

Return value

0 upon success, non-zero value on failure.

Example

#include <csignal>
#include <iostream>

const char* signal_to_string(int signal)
{
#define SIG_CASE(sig) case sig: return #sig;
    switch(signal)
    {
        SIG_CASE(SIGABRT) SIG_CASE(SIGFPE) SIG_CASE(SIGILL)
        SIG_CASE(SIGINT) SIG_CASE(SIGSEGV) SIG_CASE(SIGTERM)
        default: return "unknown";
    }
#undef SIG_CASE
}

volatile sig_atomic_t gSignalStatus;

extern "C" void signal_handler(int signal)
{
    gSignalStatus = signal;
}

int main(void)
{
    signal(SIGINT, signal_handler);

    std::cout << "Signal value:   " << signal_to_string(gSignalStatus) <<'\n';
    std::cout << "Sending signal: " << signal_to_string(SIGINT) << '\n';
    raise(SIGINT);
    std::cout << "Signal value:   " << signal_to_string(gSignalStatus) <<'\n';
}

Output:

Signal value:   unknown
Sending signal: SIGINT
Signal value:   SIGINT

See also

sets a signal handler for particular signal
(function) [edit]
C documentation for raise