fork download
  1.  
  2. #include<stdio.h>
  3. #include<unistd.h>
  4. #include<stdlib.h>
  5. #include<sys/wait.h>
  6.  
  7. int main()
  8. {
  9. int fd[2];
  10. pipe(fd);
  11.  
  12. if(fork()==0)
  13. {
  14. close(fd[0]);
  15. printf("Child PID = %d\n",getpid());
  16. close(fd[1]);
  17. exit(0);
  18. }
  19. else
  20. {
  21. close(fd[1]);
  22. wait(NULL);
  23. printf("Parent PID = %d\n",getpid());
  24. close(fd[0]);
  25. }
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Child PID = 3
Parent PID = 2