Reputation: 6116
I read in Beej's fork()
primer that when I call pid = fork();
, the parent process gets pid of child process, while inside the child process pid = 0
.
Now, since child process starts executing part of code after the fork()
statement, how does pid
gets value0
?
Upvotes: 0
Views: 5134
Reputation: 215257
Whoever told you "the child process starts executing after the fork statement" was poorly expressing the intended meaning. The point at which two processes come to exist is, conceptually, "inside" the fork call; it returns once in the parent and once in the child, with different return values in each.
Upvotes: 13