0xF1
0xF1

Reputation: 6116

How does "pid = fork();" assigns "pid = 0" in child process?

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

Answers (1)

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

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

Related Questions