fork(1) download
  1. #include "stdio.h"
  2. #include "unistd.h"
  3. void red()
  4. {
  5. printf("red\n");
  6. }
  7.  
  8. void green()
  9. {
  10. printf("green\n");
  11. }
  12.  
  13. int main()
  14. {
  15. fork();
  16. int color=fork();
  17. printf("%d\n",color);
  18. if(color==0)
  19. fork();
  20. red();
  21. // if(color==0)
  22. // fork();
  23. green();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 1720KB
stdin
Standard input is empty
stdout
12705
red
12706
red
0
red
0
red
0
red
0
red