Not so complicated: half of the fork () syscall kernel can determine the difference between two processes through the process control unit, as you mentioned, but you donβt even have to. So, the pseudo code looks like this:
int fork() { int orig_pid = getpid(); int new_pid = kernel_do_fork();
Edit: The naive version works the way you describe - it creates a new process context, copies all the associated stream contexts, copies all pages and file associations, and the new process is placed on the "ready to start" list.
I think that the part that you confuse is that when these processes resume (that is, when the parent returns from kernel_do_fork and the child is assigned for the first time), it starts in the middle of the function (i.e. the execution of this first " if a" ). This is an exact copy - both processes will perform the second half of the function.
Paul betts
source share