C library functions -sigdelset()
C Standard Library - <signal.h>
Description
sigdelsetThe function is a function in the C standard library, used to delete a specific signal from a signal set. This function is defined in<signal.h>In the header file.
Syntax
int sigdelset(sigset_t *set, int signo);
Parameter
sigset_t *set: points to asigset_tA signal set variable of type.int signo: the signal number to be deleted 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 usingsigdelsetAn example program for the function to delete a specific signal from a signal set. The program initializes a signal set containing all signals, then deletes from the signal setSIGINTsignal, and checks whether the signal set containsSIGINTsignal.
Example
#include <signal.h>
int main() {
sigset_t set;
// Initialize the signal set, containing all signals
if (sigfillset(&set) == -1) {
perror("sigfillset");
return 1;
}
// Remove 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;
}
A possible output of running the above example program is as follows:
SIGINT is not in the set
The program initializes a signal set containing all signals, then deletes from the signal setSIGINTsignal, and checks whether the signal set containsSIGINTsignal, the results show thatSIGINTThe signal is no longer in the signal set.
Explanation
sigset_t set;: defines a signal set variable.- Usage
sigfillsetThe function initializes the signal set to contain all signals. - Usage
sigdelsetThe function deletes the signal from the signal set.SIGINTsignal. - Usage
sigismemberThe function checks whether the signal set containsSIGINTsignal. - The output shows
SIGINTThe signal has been removed 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 setserrnoto indicate the error type.