win32 signal

The signal function enables a process to choose one of several ways to handle an interrupt signal from the operating system. The sig argument is the interrupt to which signal responds; it must be one of the following manifest constants, which are defined in SIGNAL.H.

 

sig value

Description

SIGABRT

Abnormal termination

SIGFPE

Floating-point error

SIGILL

Illegal instruction

SIGINT

CTRL+C signal

SIGSEGV

Illegal storage access

SIGTERM

Termination request

If sig is not one of the above values, the invalid parameter handler is invoked, as defined in Parameter Validation . If execution is allowed to continue, this function sets errno to EINVALand returns SIG_ERR.

By default, signal terminates the calling program with exit code 3, regardless of the value of sig.

Example :


int main(void)
{    

    typedef void (*SignalHandlerPointer)(int);

    SignalHandlerPointer previousHandler;
    previousHandler = signal(SIGABRT, SignalHandler);
    previousHandler = signal(SIGINT, SignalHandler);
    previousHandler = signal(SIGTERM, SignalHandler);
    previousHandler = signal(SIGBREAK, SignalHandler);

    //abort();
    while (1)
    {
        Sleep(100);
    }
void SignalHandler(int signal)
{
    if (signal == SIGABRT)
    {
        // abort signal handler code
    } else 
    {
        // ...
    }

    printf("____ signal: %d  
", signal);
}

http://msdn.microsoft.com/en-us/library/xdkz3x12.aspx

Send signal

原文地址:https://www.cnblogs.com/iclk/p/3560081.html