Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5.  
  6. int mode = 0;
  7.  
  8. void funct1(int sig)
  9. {
  10.     mode = 0;
  11.     return;
  12. }
  13. void funct2(int sig)
  14. {
  15.     mode = 1;
  16.     return;
  17. }
  18.  
  19. int main(void)
  20. {
  21.     signal(SIGUSR1, funct1);
  22.     signal(SIGUSR2, funct2);
  23.  
  24.     int pid = getpid();
  25.     printf("%d\n", pid);
  26.     fflush(stdout);
  27.  
  28.     int a;
  29.     while (scanf("%d", &a) > 0)
  30.     {
  31.         if(!mode)
  32.         {
  33.             printf("%d\n", -a);
  34.             fflush(stdout);
  35.         }
  36.         else
  37.         {
  38.             printf("%d\n", a*a);
  39.             fflush(stdout);
  40.         }
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement