Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <signal.h>
- #define MILI_SEC 1000000
- #define IGNORE_VALUE 1000
- const long INTERVAL_MS = 500*MILI_SEC;
- unsigned int i=0,tmp=0;
- unsigned int RUNNING_FLAG = 1;
- unsigned int IGNORE_FLAG = 0;
- //Reakcje na sygnał
- void SIGALRM_handler(int signalNumber);
- void SIGTERM_handler(int signalNubmer);
- void SIGUSR1_handler(int signalNumber);
- int main()
- {
- struct timespec sleepValue={0};
- sleepValue.tv_nsec = INTERVAL_MS;
- //wyłapywanie sygnałów
- signal(SIGALRM,SIGALRM_handler);
- signal(SIGTERM,SIGTERM_handler);
- signal(SIGUSR2,SIG_IGN); //ignorowanie syganłu
- signal(SIGUSR1,SIGUSR1_handler);
- while(RUNNING_FLAG)
- {
- nanosleep(&sleepValue, NULL);
- printf("%d %d\n",i, IGNORE_FLAG);
- ++i;
- if(IGNORE_FLAG == 1){
- if(i>tmp+IGNORE_VALUE){
- IGNORE_FLAG = 0;
- }
- }
- }
- return 0;
- }
- void SIGALRM_handler(int signalNumber)
- {
- printf("Wylapano sygnal: %d \n",signalNumber);
- printf("Zakonczenie dzialania programu... \n");
- RUNNING_FLAG=0;
- }
- void SIGTERM_handler(int signalNumber)
- {
- printf("Wylapano sygnal: %d \n",signalNumber);
- }
- void SIGUSR1_handler(int signalNumber)
- {
- if(IGNORE_FLAG == 0) {
- printf("Wylapano sygnal: %d \n",signalNumber);
- IGNORE_FLAG = 1;
- tmp=i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement