Using a simple C program that calls `fork()`, explain the sequence of events that occurs from the parent process calling `fork()` to both the parent and child processes continuing execution.
printf("This is the parent process, child PID:%d\n",pid);
}
return 0;
}
This program works as: firstly, the parent calls fork triggering a system call to the kernel. Then the kernel allocates a new task_struct for the child and copies the parent's task_struct. Then we check the return value from fork, in parent's process context it is set to child's PID, whereas in child's its set to 0. Then the kernel switches back to user mode and both process continue execution from the point immediately following the fork call. Parent process executes in the block, where return value is child's PID, whereas child process executes in the block where return value is 0. After that both process run independently, following the copy-on-write method.