Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. //#include <>
  6.  
  7. int fd[2];
  8. char *str;
  9. int l,max;
  10. void hndr (int sig)
  11. {
  12.     if (sig == SIGUSR1) {
  13.         if (!fork()){ //процесс-сын
  14.             fgets(str, 100, stdin);
  15.             l = strlen(str);
  16.             kill(getppid(),SIGUSR1);
  17.             for (;;);
  18.         }
  19.     }
  20.         if (sig == SIGINT){
  21.             read (fd[1],&l,sizeof (l));
  22.             if (l>max) max = l;
  23.         }
  24.         if (sig == SIGQUIT){
  25.             _exit (0);
  26.         }
  27. }
  28.  
  29.  
  30. int main (void)
  31. {
  32.     str = calloc (102, sizeof(char));
  33.     signal(SIGUSR1, hndr);
  34.    
  35.     if (!fork()){ //процесс-сын
  36.         pipe(fd);
  37.         fgets(str, 1000, stdin);
  38.     l = strlen(str);
  39.         write(fd[1],l,sizeof (l));
  40.         kill(getppid(),SIGUSR1);
  41.         for (;;);
  42.     }
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement