Advertisement
tsnaik

OS lab 6

Aug 17th, 2015
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. /**
  2. *
  3. *OS Lab 6
  4. *18/08/2015
  5. *@Tanmay Naik
  6. */
  7.  
  8. 1. Pipe
  9.  
  10. #include<stdio.h>
  11. #include<unistd.h>
  12. #include<sys/types.h>
  13. #include<string.h>
  14.  
  15. void main()
  16. {
  17.     int fd[2], pid;
  18.    
  19.     char *m = "Hello msg";
  20.     char m1;
  21.    
  22.     pipe(fd);
  23.     pid=fork();
  24.    
  25.     if(pid==0)
  26.     {
  27.         close(fd[0]);
  28.         write(fd[1],m,strlen(m));
  29.        
  30.     }  
  31.     else
  32.     {
  33.         close(fd[1]);
  34.         while(read(fd[0],&m1,1))
  35.         {
  36.             printf("%c",m1);           
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement