Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. //
  2. // Created by resolution on 20.11.17.
  3. //
  4.  
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <string.h>
  10.  
  11. #define MAXBUFF 100
  12. int main(int argc, char* argv[])
  13. {
  14.     int fd[2];
  15.     int pid;
  16.     char buffor[] = "pepethefrog.png";
  17.     char out[MAXBUFF];
  18.     int licz;
  19.     if(pipe(fd) == -1 )
  20.     {
  21.         fprintf (stderr, "Nie udalo sie stowrzyc potoku: %s", strerror (errno));
  22.         exit(2);
  23.     }
  24.     if((pid = fork()) == -1)
  25.     {
  26.         fprintf (stderr, "Nie udalo sie sforkowac: %s", strerror (errno));
  27.         exit(1);
  28.     }
  29.     if(pid == 0) // potomek
  30.     {
  31.         write(fd[1], buffor, (strlen(buffor) + 1 ));
  32.         dup2(0, fd[0]);
  33.         //execlp("display", "display", NULL);
  34.         execlp("eog", "eog", NULL);
  35.     }
  36.     else    // rodzic
  37.     {
  38.         close(fd[1]);
  39.         licz  = read(fd[0], out, sizeof(out));
  40.         printf("Mam: %s", out);
  41.         write(1,buffor,licz);
  42.         //execlp("eog", "eog", NULL);
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement