fork download
  1. #include <unistd.h>
  2. #include <string.h>
  3.  
  4. static void log_line(const char *s) {
  5. write(1, s, strlen(s)); // fd 1 = stdout
  6. }
  7.  
  8. int main(void) {
  9. int x = 5, y = 2, z = 30;
  10.  
  11. x = fork();
  12. y = fork();
  13.  
  14. if (x != 0) log_line("Type 1\n");
  15. if (y != 0) log_line("Type 2\n");
  16.  
  17. z = fork();
  18.  
  19. if ((x > 0) || (y > 0) || (z > 0)) log_line("Type 3\n");
  20. if ((x == 0) && (y == 0) && (z != 0)) log_line("Type 4\n");
  21. if ((x != 0) && (y != 0) && (z != 0)) log_line("Type 5\n");
  22. if ((y != 0) && (z == 0)) log_line("Type 6\n");
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Type 1
Type 2
Type 3
Type 5
Type 3
Type 6
Type 1
Type 3
Type 2
Type 3
Type 3