fork download
  1. /* main program illustrating the UNIX fork() system call.
  2. Compile using cc -o main main.c
  3. */
  4. #include <stdio.h>
  5. main() {
  6. if (fork() != 0) {
  7. if (fork() != 0) {
  8. printf("hello1 %i\n", getpid());
  9. }
  10. else {
  11. fork();
  12. }
  13. printf("hello2 %i\n", getpid());
  14. }
  15. else {
  16. if (fork != 0) {
  17. printf("hello3 %i\n", getpid());
  18. }
  19. else {
  20. fork();
  21. }
  22. printf("hello4 %i\n", getpid());
  23. }
  24. printf("hello5 %i\n", getpid());
  25. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
hello1 748909
hello2 748909
hello5 748909
hello2 748913
hello5 748913
hello3 748912
hello4 748912
hello5 748912