DEV Community

Khadijah (Dana Ordalina)
Khadijah (Dana Ordalina)

Posted on

Supplemental Reading for Windows Signal

Signal

Sets interrupt signal handling.

Syntax

C

void __cdecl *signal(int sig, int (*func)(int, int));
Enter fullscreen mode Exit fullscreen mode

Parameters
sig
Signal value.

func
The second parameter is a pointer to the function to be executed. The first parameter is a signal value, and the second parameter is a subcode that can be used when the first parameter is SIGFPE.

Remarks

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 isn't 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 EINVAL and returnsSIG_ERR.

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

Top comments (1)

Collapse
 
bhavin-allinonetools profile image
Bhavin Sheth

Good reminder. One thing I learned the hard way is that signal() behavior on Windows is limited compared to Linux — especially for things like SIGTERM and SIGINT. Also, always keep the handler simple, because doing heavy work inside it can cause unstable behavior. It’s best used for cleanup and safe exit, not complex logic.