raise()

Declaration

int raise(int iSignal);

Description:

This function sends a signal to the executing program. If the function is successful, it returns 0. If not, it returns a nonzero value.

Example

#include <iostream>
#include <csignal>

void InterruptHandler(int iArgument) {
    std::cout << "Inside Handler" << std::endl;
    std::cout << "Handler Argument = " << iArgument << std::endl;
}

int main() {
    using namespace std;

    void (*pfnOldHandler)(int);

    pfnOldHandler       = signal(SIGTERM, InterruptHandler);
    int iReturnValue    = raise(SIGTERM);
    cout << "Return value = " << iReturnValue << endl;
    
    return 0;
}

Output:

raise() Output