You are not logged in.
Pages: 1
I am sorry my English is poor.
Look:
<b>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
void printsigset(sigset_t *set)
{
int i;
for(i=1;i<NSIG;i++)
{
if(sigismember(set,i))
putchar('1');
else
putchar('0');
}
printf("\n");
}
void handler(int);
int main()
{
sigset_t pset;
sigset_t bset;
sigemptyset(&pset);
sigemptyset(&bset);
signal(SIGINT,handler);
signal(SIGQUIT,handler);
sigaddset(&bset,SIGINT);
sigprocmask(SIG_BLOCK,&bset,NULL);
for(;;)
{
sigpending(&pset);
printsigset(&pset);
sleep(1);
}
return 0;
}
void handler(int sig)
{
if(sig==SIGINT)
printf("recv sig=%d\n",sig);
else if(sig==SIGQUIT)
{
sigset_t uset;
sigemptyset(&uset);
sigaddset(&uset,SIGINT);
sigprocmask(SIG_UNBLOCK,&uset,NULL);
}
}
</b>
The first I press ctrl+c,the second bit of pending word is 1;the second
I press ctrl+\,the second bit of pending word is 0;but the third time
I press ctrl+c the second bit of pending word is 1.But the third time
the codes run in for(;;) statements,and it does not run
<b>
sigaddset(&bset,SIGINT);
sigprocmask(SIG_BLOCK,&bset,NULL);
</b>
why the second bit of pendingk word is 1?
Offline
Please use code tags when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code
Moving to Programming & Scripting...
Offline
You have too many sigset_t's for what you are trying to do...
I don't know why you swap between SET's like you do.
In printsigset try a printf instead of putchar to see what's happening
if(sigismember(set,i))
printf("%d", i);
it's the same value you get printed out in handler.
If you use puts at the start of your for loop you'll see it runs straight away
for(;;)
puts("looping");
...
HTH
You're just jealous because the voices only talk to me.
Offline
Pages: 1