Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. sigaction - why don't we have to reset the handler?
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <signal.h>
  5.  
  6. void func(int sig)
  7. {
  8.  printf("caught signal:%dn",sig);
  9.  // Not needed to reset handler. Why?
  10. }
  11.  
  12. int main()
  13. {
  14.  struct sigaction sa;
  15.  
  16.  sa.sa_handler=(void*)func;
  17.  sigaction(SIGRTMIN,&sa,NULL);
  18.  kill(0,SIGRTMIN);
  19.  kill(0,SIGRTMIN);
  20.  kill(0,SIGRTMIN);
  21. }
  22. Output:
  23. [root@dhcppc0 signals]# ./a.out
  24.      caught signal:34
  25.      caught signal:34
  26.      caught signal:34 (3 times signal caught by same handler without resetting handler)