C Library Function - sigfillset()
Description
sigfillset The function is a function in the C standard library, used to initialize a signal set so that it contains all defined signals. This function is defined in header.
Syntax
int sigfillset(sigset_t *set);
Parameters
sigset_t *set: points to asigset_tvariable of type , which will be initialized to a signal set containing all signals.
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 sigfillset Example program demonstrating the function initializing a signal set. The program initializes a signal set to contain all signals and checks whether it contains a specific signal.
Example
#include
#include
int
main
(
)
{
sigset_t set
;
// initialize the signal set to include all signals
if
(
sigfillset
(
&
set
)
==
1
)
{
perror
(
"sigfillset"
)
;
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
;
}
Running the above example program may produce the following output:
SIGINT is in the set
The program initializes the signal set to contain all signals and checks whether the signal set contains SIGINT signal, and the result shows that SIGINT signal is in the signal set.
Explanation
sigset_t set;: defines a signal set variable.- Use
sigfillsetThe function initializes the signal set to contain all signals. - Use
sigismemberThe function checks whether the signal set containsSIGINTsignal after 5 seconds. - The output shows that
SIGINTthe signal is in the signal set after initialization.
Notes
sigfillsetThe function is used to initialize a signal set so that it contains all defined signals.- The initialized signal set can be used for subsequent signal operations, such as deleting a specific signal.
C Standard Library -