Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #define MAX 512
  5. main(int argc, char* argv[]) {
  6.   int pd[2];
  7.   pipe(pd);
  8.     if(fork() == 0)
  9.     {
  10.         dup2(pd[1], 1);
  11.             execvp("ls", argv);
  12.     }
  13.     else
  14.     {
  15.         wait(NULL);
  16.         if(fork() == 0)
  17.         {
  18.             char buf[MAX];
  19.             int lb, i;
  20.             close(pd[1]);
  21.             while((lb=read(pd[0],buf,MAX))>=0)
  22.             {
  23.                   for(i=0; i<lb; i++)
  24.                         buf[i] = toupper(buf[i]);
  25.                         write(1, buf,lb);
  26.                 exit(0);   
  27.             }
  28.         }
  29.         wait(NULL);
  30.         wait(NULL);
  31.         printf("ojciec3\n");
  32.         printf("Koniec3\n");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement