From man sigprocmask:
"If oset is not null, it is set to the previous value of the signal mask."
My questions: Without running or debugging the program,
After executing line 10, the value of the old signal mask is stored into
y. Since there were no blocked signals before this line was executed, what is the value ofy?Is there a way to determine the value of
zafter executing line 14?
1 void my_sig_handler(int sig){
2 write(1, "a", 1);
3 }
4 int main(){
5 signal(SIGINT, my_sig_handler);
6 sigset_t x, y, z;
7 sigemptyset(&x);
8 sigaddset(&x, SIGINT);
9
10 sigprocmask(SIG_BLOCK, &x, &y);
11 write(1,"1",1);
12 do_some_work();
13 write(1,"2",1);
14 sigprocmask(SIG_SETMASK, &y, &z);
15
16 exit(0);
17 }
You can test membership in a signal set with
sigismember. Historically POSIX omitted a way to identify the range of values that might be signal numbers that you need to test, but all historical systems have_NSIGorNSIGdefined to tell you this, and future POSIX is adding it.Note that you can't in general assume
yis empty after line 10, since signal mask is inherited acrossfork/exec. Your program may have been started with some signals masked.