Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- #include <sys/types.h>
- typedef void (*sighandler_t)(int);
- sighandler_t signal (int signo, sighandler_t handler);
- int count_stop = 0;
- int count_kill = 0;
- void nie_zatrzymasz_mnie1( int sig_no )
- {
- if(count_stop < 5)
- {
- signal( SIGTSTP, nie_zatrzymasz_mnie1 );
- printf("CTRL + Z po raz %d\n", count_stop+1);
- fflush(stdout);
- count_stop++;
- }
- else
- {
- signal( SIGTSTP, SIG_DFL );
- count_stop = 0;
- }
- }
- void nie_zatrzymasz_mnie2( int sig_no )
- {
- if(count_kill < 5)
- {
- signal( SIGINT, nie_zatrzymasz_mnie2 );
- printf("CTRL + C po raz %d\n", count_kill+1);
- count_kill++;
- }
- else
- {
- signal( SIGINT, SIG_DFL );
- count_kill = 0;
- }
- }
- /*
- * FUNKCJA KILL TO IMPLEMENTACJI
- * FUNKCJA KILL TO IMPLEMENTACJI
- * FUNKCJA KILL TO IMPLEMENTACJI
- * FUNKCJA KILL TO IMPLEMENTACJI
- */
- int main(int argc, char** argv)
- {
- signal( SIGTSTP, nie_zatrzymasz_mnie1 );
- signal( SIGINT, nie_zatrzymasz_mnie2 );
- for( ;; )
- {
- pause();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment