fork download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. int main() {
  5. fork(); // Creates a child process
  6. int pid = fork(); // Creates another child process and stores its PID
  7.  
  8. printf("hello"); // This line will be executed by all processes
  9.  
  10. if (pid > 0) { // Code executed only by the parent process
  11. fork(); // Creates yet another child process
  12. if (pid == 0) // Code executed only by the child processes created by the second fork
  13. printf("hello");
  14. }
  15.  
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 5292KB
stdin
45
stdout
hellohellohello