fork download
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8. pid_t id1 = fork();
  9. pid_t id2 = fork();
  10.  
  11. if (id1 > 0 && id2 > 0) {
  12. printf("Parent Terminated\n");
  13. } else {
  14. pid_t id3 = fork();
  15. if (id3 > 0) {
  16. printf("Child Terminated\n");
  17. } else {
  18. printf("Grandchild Terminated\n");
  19. exit(0);
  20. }
  21. }
  22. printf("Bye\n");
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Parent Terminated
Bye
Child Terminated
Bye