C Library Functionssigismember()
C Standard Library - <signal.h>
Description
sigismemberThe function is a function in the C standard library, used to check whether a specific signal is in the signal set. This function is defined in<signal.h>In the header file.
Syntax
int sigismember(const sigset_t *set, int signo);
Parameter
const sigset_t *set: points to asigset_tA signal set variable of type.int signo: The signal number to check.
Return Value
- If the signal is in the signal set, return 1.
- If the signal is not in the signal set, return 0.
- On error, return -1 and set
errnoto indicate the type of error.
Example
The following is an example usingsigismemberAn example program for the function to check whether a signal set contains a specific signal. The program initializes an empty signal set, addsSIGINTsignal to the signal set, and checks whether the signal set containsSIGINTsignal.
Example
#include <signal.h>
int main() {
sigset_t set;
// Initialize the signal set to empty
if (sigemptyset(&set) == -1) {
perror("sigemptyset");
return 1;
}
// add SIGINT to the signal set
if (sigaddset(&set, SIGINT) == -1) {
perror("sigaddset");
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");
}
// check whether the signal set contains SIGTERM
if (sigismember(&set, SIGTERM)) {
printf("SIGTERM is in the set\n");
} else {
printf("SIGTERM is not in the set\n");
}
return 0;
}
The possible output of running the above example program is as follows:
SIGINT is in the set SIGTERM is not in the set
The program initializes an empty signal set, andSIGINTsignal to the signal set, and checks whether the signal set containsSIGINTandSIGTERMsignal, the results showSIGINTsignal is in the signal set, whileSIGTERMsignal is not in the signal set.
Explanation
sigset_t set;: Defines a signal set variable.- Usage
sigemptysetThe function initializes the signal set to empty. - Usage
sigaddsetThe function willSIGINTThe signal is added to the signal set. - Usage
sigismemberThe function checks whether the signal set containsSIGINTandSIGTERMsignal. - The output shows
SIGINTsignal is in the signal set, whileSIGTERMsignal is not in the signal set.
Notes
sigismemberThe function is used to check whether a specific signal is in the signal set.- If the signal number is invalid,
sigismemberthe function will return -1 and seterrnoto indicate the type of error.