fork download
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4.  
  5. int main()
  6. {
  7. pid_t pid1,pid11,pid111, pid2,pid21,pid22;
  8. pid1=fork();
  9. if(pid1=-1){
  10. printf("error");
  11.  
  12. }else if(pid1==0){
  13. printf("child 1.0 my ppid:%d and my pid: %d",getppid(),getpid());
  14. pid11=fork();
  15. if(pid11==0){
  16. printf("child 1.1 my ppid:%d and my pid: %d",getppid(),getpid());
  17.  
  18. pid111=fork();
  19. if(pid111==0){
  20. printf("child 1.1.1 my ppid:%d and my pid: %d",getppid(),getpid());
  21. }
  22. }
  23.  
  24. }else{
  25. pid2=fork();
  26. if(pid2==0){
  27. printf("child 2.0 my ppid:%d and my pid: %d",getppid(),getpid());
  28. pid21=fork();
  29. if(pid21==0){
  30. printf("child 2.1 my ppid:%d and my pid: %d",getppid(),getpid());
  31. }else{
  32. pid22=fork();
  33. if(pid22==0){
  34. printf("child 2.2 my ppid:%d and my pid: %d",getppid(),getpid());
  35. }
  36. }
  37. }
  38. }
  39. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
errorerror