Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sched.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- volatile sig_atomic_t cnt;
- volatile sig_atomic_t must_exit = 0;
- void handle_sigterm(int signum)
- {
- must_exit = 1;
- }
- void handle_sigusr1(int signum)
- {
- cnt += 1;
- printf("%d\n", cnt);
- fflush(stdout);
- }
- void handle_sigusr2(int signum)
- {
- cnt *= -1;
- printf("%d\n", cnt);
- fflush(stdout);
- }
- int main()
- {
- struct sigaction action_usr1;
- memset(&action_usr1, 0, sizeof(action_usr1));
- action_usr1.sa_handler = handle_sigusr1;
- action_usr1.sa_flags = SA_RESTART;
- sigaction(SIGUSR1, &action_usr1, NULL);
- struct sigaction action_usr2;
- memset(&action_usr2, 0, sizeof(action_usr2));
- action_usr2.sa_handler = handle_sigusr2;
- action_usr2.sa_flags = SA_RESTART;
- sigaction(SIGUSR2, &action_usr2, NULL);
- struct sigaction action_term;
- memset(&action_term, 0, sizeof(action_term));
- action_term.sa_handler = handle_sigterm;
- action_term.sa_flags = SA_RESTART;
- sigaction(SIGTERM, &action_term, NULL);
- printf("%d\n", getpid());
- fflush(stdout);
- scanf("%d", &cnt);
- while (!must_exit) {
- pause();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement