sigset_t new,old;
sigemptyset(&new);
sigaddset(&new, SIGINT);
sigaddset(&new, SIGTSTP);
sigprocmask(SIG_BLOCK, &new, &old);
//Before son
(exec,(other stuff...))
// ON Father
sigprocmask(SIG_UNBLOCK, &new, &old);
sigprocmask(SIG_SETMASK, &old, NULL);
I'm doing a project, being this, a shell program. I have already finished the first part of the project which is the use of pipes, forks, exec, I/O files. Now I'm crashing my project in order to find bugs and I came with this one that has become very annoying to me, because I can't find the solution. Sorry, but I cant post all my code here, because it might be copied by my classmates.
Looking at the code above, If I execute my program and spam the CTRL Z and CTRL C, right at the beginning of execution without inserting any command, my handler will enter in action saying that the program cant be suspended or paused, and if I write a new command being this,"sleep 5", and spam again, it is in a status of "ignore" because of the sigset_t , after the command finishes it gives me the messages of the handler, because "sleep 5" suspends everything, and is waiting for me to insert a new command, if I spam again my handler doesn't give any message when it should. It like the signals that I added are still blocked. Does SIG_UNBLOCK unblocks the whole set of signals that I added or just one?
sigprocmask(SIG_SETMASK, &old, NULL);undo your previoussigprocmask(SIG_UNBLOCK, &new, &old);... read the doc. - Stargateur