fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //#include <stdio.h>
  5. #include <time.h>
  6. //#include <iostream>
  7. #include <unistd.h>
  8. #include <sys/types.h>
  9. #include <sys/wait.h>
  10. //using namespace std;
  11.  
  12. int main() {
  13. // your code goes here
  14. time_t start;
  15. time_t end;
  16. int i=0;
  17. int pid;
  18.  
  19. start= time(NULL);
  20. printf ("Αρχική τιμή δευτερολέπτων %d\n", start);fflush(stdout);
  21.  
  22. pid=fork();
  23. printf ("1 %d\n", pid);fflush(stdout);
  24. while (i<2){
  25. if (pid>0){
  26. fork();
  27. wait(NULL);
  28. i++;
  29. }
  30. }
  31.  
  32. printf ("check \n");fflush(stdout);
  33.  
  34. printf("2 %d\n", pid);fflush(stdout);
  35.  
  36. if (pid>0){
  37. end= time (NULL);
  38. printf ("3 %d\n", end-start);fflush(stdout);
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 15232KB
stdin
Standard input is empty
stdout
Αρχική τιμή δευτερολέπτων 1547399518
1 31596
1 0
check 
2 31596
3 0
check 
2 31596
3 0
check 
2 31596
3 0
check 
2 31596
3 0