C Library Function - sigemptyset()
sigpending The function is a function in the C standard library, used to get the pending (unhandled) signal set of the current process. A pending signal is one that has been blocked but not yet handled. This function is defined in header.
Syntax
int sigemptyset(sigset_t *set);
Parameters
sigset_t *set: points to asigset_tvariable of type , which will be initialized to an empty signal set.
Return Value
- Returns 0 on success.
- Returns -1 on failure and sets
errnoto indicate the error type.
Example
The following is an example of using sigemptyset Example program demonstrating the function initializing a signal set. The program initializes a signal set and checks whether it contains a specific signal.
Example
#include
#include
int
main
(
)
{
sigset_t set
;
// initialize the signal set to empty
if
(
sigemptyset
(
&
set
)
==
1
)
{
perror
(
"sigemptyset"
)
;
return
1
;
}
// check whether the signal set contains SIGINT
if
(
sigismember
(
&
set
,
SIGINT
)
)
{
printf
(
"SIGINT is in the set\n"
)
;
}
else
{
printf
(
"SIGINT is not in the set\n"
)
;
}
return
0
;
}
After compiling and running the program, the output will be:
SIGINT is not in the set
The program first blocks SIGINT signal, then sends the signal, and uses sigpending Checks SIGINT whether it is in the pending signal set. Finally, the program restores the original signal mask, and catches the SIGINT signal and executes the signal handler.
Parsing
sigset_t set;: defines a signal set variable.- Use
sigemptysetThe function initializes the signal set to empty. - Use
sigismemberThe function checks whether the signal set containsSIGINTsignal after 5 seconds. - The output shows that
SIGINTThe signal is not in the empty signal set after initialization.
Notes
sigemptysetThe function is used to initialize a signal set so that it does not contain any signals.- The initialized signal set can be used for subsequent signal operations, such as adding or deleting signals.
C Standard Library -