Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <signal.h>
int sigpending(sigset_t *set);
Returns the union of the set of signals that are blocked from delivery and pending for the calling thread and the set that are pending for the process. If there is only one thread, it does the same for the calling process. This information is represented as a signal set stored in set. For more information on examining the signal set pointed to by set, see sigismember() — Test if a signal is in a signal mask.
The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.
If successful, sigpending() returns 0.
If unsuccessful, sigpending() returns -1.
There are no documented errno values.
⁄* CELEBS22
This example returns blocked or pending signals.
*⁄
#define _POSIX_SOURCE
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void catcher(int signum) {
puts("inside catcher!");
}
void check_pending(int signum, char *signame) {
sigset_t sigset;
if (sigpending(&sigset) != 0)
perror("sigpending() error");
else if (sigismember(&sigset, signum))
printf("a %s signal is pending\n", signame);
else
printf("no %s signals are pending\n", signame);
}
main() {
struct sigaction sigact;
sigset_t sigset;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigact.sa_handler = catcher;
if (sigaction(SIGUSR1, &sigact, NULL) != 0)
perror("sigaction() error");
else {
sigemptyset(&sigset);
sigaddset(&sigset, SIGUSR1);
if (sigprocmask(SIG_SETMASK, &sigset, NULL) != 0)
perror("sigprocmask() error");
else {
puts("SIGUSR1 signals are now blocked");
kill(getpid(), SIGUSR1);
printf("after kill: ");
check_pending(SIGUSR1, "SIGUSR1");
sigemptyset(&sigset);
sigprocmask(SIG_SETMASK, &sigset, NULL);
puts("SIGUSR1 signals are no longer blocked");
check_pending(SIGUSR1, "SIGUSR1");
}
}
}
SIGUSR1 signals are now blocked
after kill: a SIGUSR1 signal is pending
inside catcher!
SIGUSR1 signals are no longer blocked
no SIGUSR1 signals are pending