Advertisement
paulogp

Signal (kill)

Jul 14th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. /* resposta a sinais (signal)
  2.  comando ps para obter o <id processo>
  3.  kill <id processo>         : emite mensagem "sinal recebido"
  4.  kill -USR1 <id processo>   : ignorado
  5.  kill -INT <id processo>    : termina programa */
  6.  
  7. // Apple Xcode
  8. // paulogp
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <signal.h>
  13.  
  14. void responder(int signum)
  15. {
  16.     printf("sinal recebido\n");
  17. }
  18.  
  19. int main (int argc, const char * argv[])
  20. {
  21.     printf("activo\n");
  22.    
  23.     struct sigaction the_action;
  24.     sigset_t the_sigset;
  25.    
  26.     the_action.sa_handler = responder;
  27.     sigaction(SIGUSR1, &the_action, NULL);
  28.     sigaction(SIGTERM, &the_action, NULL);
  29.    
  30.     sigemptyset(&the_sigset);
  31.    
  32.     sigaddset(&the_sigset, SIGUSR1);
  33.     sigprocmask(SIG_SETMASK, &the_sigset, NULL);
  34.    
  35.     while (1); // infinite loop
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement