Home > OS >  Linux multithreaded problem
Linux multithreaded problem

Time:10-24

Why the output of the code below is
1
1
And the result that I introduced to is
1
 
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; Unistd. H>
Void create_pth (int n) {
Pid_t pid;
Pid=fork ();
If (pid<0 {
Printf (" error ");
exit(0);
{} else if (pid==0)
If (n<1) {
Create_pth (n + 1);
Printf (" % d \ n ", n);
} else {
Sleep (10);
}
} else {
Wait (NULL).
}
}
Int main () {
Create_pth (0);
return 0;
}
  • Related