fork download
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4. using namespace std;
  5.  
  6. int main(int argc, char* argv[]) {
  7.  
  8. pid_t ret1 = 0;
  9. pid_t ret2 = 0;
  10. for (int i = 0; i < 3 ; i ++)
  11. {
  12. ret1 = fork();
  13. if ( ret1 != 0)
  14. break;
  15. else
  16. ret2 = fork();
  17. }
  18. printf ( "hello\n" );
  19. }
  20.  
  21.  
  22.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
hello
hello
hello