Guest User

Untitled

a guest
Jan 6th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. int main(int argc, char *argv[])
  2. {
  3. int fd[2];
  4. pid_t pid;
  5. char buf;
  6. pipe( fd );
  7. pid = fork();
  8. switch( fork() ){
  9. case -1:
  10. perror( "fork()" );
  11. exit( 1 );
  12. case 0:
  13. close(fd[0]);
  14. while (read(0, &buf, 1) > 0) {
  15. write(fd[1], &buf, 1);
  16. }
  17. write(1, "Death childn", 12);
  18. close(fd[1]);
  19. break;
  20. default:
  21. close(fd[1]);
  22. while (read(fd[0], &buf, 1) > 0) {
  23. write(1, &buf, 1);
  24. }
  25. write(1, "Death parentn", 12);
  26. close(fd[0]);
  27. wait(NULL);
  28. break;
  29. }
  30. }
  31.  
  32. while (read(0, &buf, 1) > 0) {
  33. write(fd[1], &buf, 1);
  34. }
  35.  
  36. while (read(fd[0], &buf, 1) > 0) {
  37. write(1, &buf, 1);
  38. }
Add Comment
Please, Sign In to add comment