14 Haziran 2015 Pazar

Blocking Signal with sigset_t,SIG_BLOCK linux example

#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
 int main(){
sigset_t base_mask, waiting_mask;

sigemptyset (&base_mask);
sigaddset (&base_mask, SIGINT);
sigaddset (&base_mask, SIGQUIT);

// when you doing some process , user would blocks signals
sigprocmask (SIG_BLOCK, &base_mask, NULL);
int test1=0,test2=0;
sleep(3);
// is there any signal which was waiting for  ?
sigpending (&waiting_mask);
if (sigismember (&waiting_mask, SIGINT)) {
  printf("user tried to finish process with SIGINT \n ");
  test1++;
}if (sigismember (&waiting_mask, SIGQUIT)) {
  printf("user tried to finish process with SIGQUIT \n ");
  test2++;
}

else if (sigismember (&waiting_mask, SIGTSTP)) {
   printf("user didn't try to finish process  \n ");
}

 printf(" time of INT %d " ,test1);
 printf("\n time of QUIT %d  " ,test2);
  printf("\n Signal will act like a normal \n times of INT :");
 //sigfillset(sigset_t *set)
   sigprocmask (SIG_UNBLOCK, &base_mask,NULL);;
   //signal(SIGINT,SIG_DFL);
   //signal(SIGQUIT,SIG_DFL);
   sigdelset (&base_mask, SIGINT);
   sigdelset(&base_mask, SIGTSTP);
 


 }

1 yorum:

  1. Lucky Club Casino Site
    Lucky Club Casino is a luckyclub casino that offers players online slots, blackjack, live dealer games and poker. It has been in operation since 2006. The casino has a good reputation in

    YanıtlaSil

Yorum yaptığınız için teşekkür ederiz.