C Library Function - sigdelset()
Description
sigdelset The function is a function in the C standard library, used to delete a specific signal from a signal set. This function is defined in header.
Syntax
int sigdelset(sigset_t *set, int signo);
Parameters
sigset_t *set: points to asigset_tsignal set variable of type .int signo: the signal number to delete from the 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 sigdelset Example program demonstrating the function deleting a specific signal from a signal set. The program initializes a signal set containing all signals, then deletes SIGINT signal from the signal set, and checks whether the signal set contains SIGINT signal after 5 seconds.
Example
#include
#include
int
main
(
)
{
sigset_t set
;
// initialize the signal set to include all signals
if
(
sigfillset
(
&
set
)
==
1
)
{
perror
(
"sigfillset"
)
;
return
1
;
}
// delete SIGINT from the signal set
if
(
sigdelset
(
&
set
,
SIGINT
)
==
1
)
{
perror
(
"sigdelset"
)
;
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 not in the set
The program initializes a signal set containing all signals, then deletes SIGINT signal from the signal set, and checks whether the signal set contains SIGINT signal, and the result shows that SIGINT The signal is no longer 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
sigdelsetThe function deletesSIGINTsignal after 5 seconds. - Use
sigismemberThe function checks whether the signal set containsSIGINTsignal after 5 seconds. - The output shows that
SIGINTThe signal has been deleted from the signal set.
Notes
sigdelsetThe function is used to delete a specific signal from a signal set.- If the signal number is invalid,
sigdelsetthe function will return -1 and seterrnoto indicate the error type.
C Standard Library -