A pointer to a function that takes an `int` as an argument and returns no value. Commonly used for signal handlers that process signals like `SIGINT` or `SIGTERM`.
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
1st Parameter
The signal number to handle, such as `SIGINT` or `SIGTERM`.
2nd Parameter Type : void (*)(int)
A pointer to a function that takes an `int` as an argument and returns no value. Commonly used for signal handlers that process signals like `SIGINT` or `SIGTERM`.
2nd Parameter
Pointer to the function that will handle the signal. Special values like `SIG_IGN` (ignore) or `SIG_DFL` (default) can also be used.
Read more about parameters of signal in parameters section
The signalfunction in C language Sets a function to handle a particular signal.
The signal function sets the handling for a specific signal. It allows a program to choose one of three ways to handle the signal: perform default processing, ignore the signal, or specify a function to be called when the signal occurs.
The signalfunction takes 2
parameters:
•
int `sig`: The signal number to handle, such as `SIGINT` or `SIGTERM`.
•
void (*)(int) `handler`: Pointer to the function that will handle the signal. Special values like `SIG_IGN` (ignore) or `SIG_DFL` (default) can also be used.
Sets a function to handle the specified signal `sig`. The `handler` can be a pointer to a custom signal handler, `SIG_IGN` to ignore the signal, or `SIG_DFL` to restore the default behavior. Returns the previous signal handler on success, or `SIG_ERR` if an error occurs.
The signal function return value :
Returns the previous value of the signal handler, or SIG_ERR on error
Output
This example sets up a signal handler for SIGINT (typically triggered by Ctrl+C). The program runs until SIGINT is received, then exits gracefully.