Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <signal.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <inttypes.h>
- int f = 0;
- void
- handler1(int sig)
- {
- f = 0;
- }
- void
- handler2(int sig)
- {
- f = 1;
- }
- int
- main(void)
- {
- struct sigaction sa1, sa2;
- sigemptyset(&sa1.sa_mask);
- sigemptyset(&sa2.sa_mask);
- sa1.sa_flags = SA_RESTART;
- sa2.sa_flags = SA_RESTART;
- sa1.sa_handler = handler1;
- sa2.sa_handler = handler2;
- sigaction(SIGINT, &sa1, NULL);
- sigaction(SIGQUIT, &sa2, NULL);
- printf("%d\n", getpid());
- fflush(stdout);
- uint32_t a, s = 0;
- while (scanf("%" PRId32, &a) == 1) {
- if (!f) {
- s += a;
- } else {
- s *= a;
- }
- printf("%" PRId32 "\n", s);
- fflush(stdout);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement