Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <dlfcn.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <signal.h>
- volatile int check = 0;
- int cnt = 0;
- struct sigaction orig_sigint_handler;
- void sigint_handler(int signo) {
- if (signo == SIGUSR1) {
- check = 0;
- } else {
- if (signo == SIGUSR2) {
- check = 1;
- } else {
- _exit(0);
- }
- }
- }
- int main(int argc, char *argv[]) {
- struct sigaction sa;
- sa.sa_handler = sigint_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- sigaction(SIGINT, &sa, &orig_sigint_handler);
- printf("%d\n", getpid());
- fflush(stdout);
- int tpr, check = 0;
- long long int to_ret;
- while (scanf("%d", &tpr) == 1) {
- if (check) {
- to_ret = trp * tpr;
- } else {
- to_ret = -tpr;
- }
- printf("%lld\n", to_ret);
- fflush(stdout);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement