fork download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. int main() {
  5. fork(); // 1st fork
  6. printf("A\n");
  7.  
  8. if (fork() == 0) { // 2nd fork (only child enters)
  9. printf("B\n");
  10. fork(); // 3rd fork (grandchild)
  11. printf("C\n");
  12. } else {
  13. printf("D\n");
  14. }
  15.  
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
A
D