Advertisement
Guest User

test.c

a guest
Nov 29th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <limits.h>
  6.  
  7. main()
  8.  
  9. {
  10.   int fd[2];
  11.   int n=0, i;
  12.  
  13.   pipe(fd);
  14.  
  15.   if (fork() == 0) {
  16.     /* Child process */
  17.    
  18.     close(1); dup(fd[1]) ; /* Redirect the stdout of this process to the pipe.*/
  19.     close(fd[0]);       /* This process will not read from the pipe in this example.  Hence we close fd[0].*/
  20.     execlp("ls","ls","-l",(char *)NULL);
  21.   } else {
  22.    
  23.     /* Parent process */
  24.     close(0); dup(fd[0]) ; /* Redirect the stdin of this process to the pipe */
  25.     close(fd[1]);/* In this example, this process will not write into the pipe. Hence we close fd[1].*/
  26.     execlp("wc","wc","-c",(char *)NULL);
  27.    
  28.   }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement