pborawski

Sygnaly cz.1

Oct 15th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5.  
  6. typedef void (*sighandler_t)(int);
  7. sighandler_t signal (int signo, sighandler_t handler);
  8. int count_stop = 0;
  9. int count_kill = 0;
  10.  
  11. void nie_zatrzymasz_mnie1( int sig_no )
  12. {
  13.         if(count_stop < 5)
  14.         {
  15.             signal( SIGTSTP, nie_zatrzymasz_mnie1 );
  16.            
  17.             printf("CTRL + Z po raz %d\n", count_stop+1);
  18.             fflush(stdout);
  19.             count_stop++;
  20.         }
  21.         else
  22.         {
  23.             signal( SIGTSTP, SIG_DFL );
  24.             count_stop = 0;
  25.         }
  26.        
  27. }
  28. void nie_zatrzymasz_mnie2( int sig_no )
  29. {
  30.     if(count_kill < 5)
  31.     {
  32.         signal( SIGINT, nie_zatrzymasz_mnie2 );
  33.         printf("CTRL + C po raz %d\n", count_kill+1);
  34.         count_kill++;
  35.     }
  36.     else
  37.     {
  38.         signal( SIGINT, SIG_DFL );
  39.         count_kill = 0;
  40.     }
  41. }
  42. /*
  43.  *      FUNKCJA KILL TO IMPLEMENTACJI
  44.  *      FUNKCJA KILL TO IMPLEMENTACJI
  45.  *      FUNKCJA KILL TO IMPLEMENTACJI
  46.  *      FUNKCJA KILL TO IMPLEMENTACJI
  47.  */
  48. int main(int argc, char** argv)
  49. {
  50.     signal( SIGTSTP, nie_zatrzymasz_mnie1 );
  51.     signal( SIGINT, nie_zatrzymasz_mnie2 );
  52.     for( ;; )
  53.     {
  54.             pause();
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment