I wrote a small piece of code. This code first blocks {SIGSEGV}, and then adds SIGRTMIN to the same set. So, my final set of signals, {SIGSEGV, SIGRTMIN}. Thus, if I use SIG_UNBLOCK, as I understand it, I first need to unlock SIGRTMIN, and then again, if I call SIG_UNBLOCK, SIGSEGV should be unlocked.
That is, 1) {SIGSEGV, SIGRTMIN} 2) SIG_UNBLOCK = unlock SIGRTMIN, 3) Call SIG_UNBLOCK = unlock SIGSEGV again. I only transfer the process to SIGRTMIN, so my second unlock should stop the process using SIGRTMIN. But this is not so. Please help.
NB: Please do not provide links to other questions on sigprocmask (), I saw them and they do not clarify my question.
enter code here
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
sigset_t old_set,new_set;
sigemptyset(&old_set);
sigemptyset(&new_set);
if(sigaddset(&old_set,SIGSEGV)==0)
{
printf("sigaddset successfully added for SIGSEGV\n");
}
sigprocmask(SIG_BLOCK,&old_set,NULL);
kill(0,SIGSEGV);
if(sigaddset(&new_set,SIGRTMIN)==0)
{
printf("sigaddset successfully added for SIGRTMIN\n");
}
sigprocmask(SIG_BLOCK,&new_set,&old_set);
kill(0,SIGSEGV);
sigprocmask(SIG_UNBLOCK,&new_set,&old_set);
sigprocmask(SIG_UNBLOCK,&new_set,&old_set);
}
Output:
[root@dhcppc0 signals]
sigaddset successfully added for SIGSEGV
sigaddset successfully added for SIGRTMIN
(Note:SIGSEGV is not received even after sigprocmask(SIG_UNBLOCK,&new_set,&old_set); a second time)