Question: syscall fork() implement help: I need to add code for #1~4 in the image only. I believe it does not need more than 4 lines.
syscall fork() implement help:

I need to add code for #1~4 in the image only.
I believe it does not need more than 4 lines.
Most lines are simple calls to helper functions from proc.c, which is the image.
Thank you
int sys_fork(struct trapframe *tf, pid_t *retval) struct trapframe ntf; int result; struct proc *newproc; /I COMMENT or REMOVE the following 4 1lines. // They are here only to force the kernel to build // despite this incomplete sys_fork implementation. (void) *tf (void) *retval;// Remove/comment this line newproc = NULL; // Remove/comment this line ntf NULL /I Remove/comment this line /I Remove/comment this line * The following steps do the following: Copy the trapframe to the heap, because we might return to * userlevel and make another syscall (changing the trapframe) *before the child runs. The child will free the copy /I Use kmalloc to allocate memory (in the heap) for the new trapframe /add code here /I Copy the content of the current trapframe to the new trapframe 2. /add code here ** // Clone the current process /add code here // Set value of retval to the new process' PID /add code here /I Create a new thread based on an existing one result - thread_fork(curthread->t_name, newproc, fork_newthread, ntf, e); if (result) t proc_unfork(newproc); kfree(ntf); return result: return e; int sys_fork(struct trapframe *tf, pid_t *retval) struct trapframe ntf; int result; struct proc *newproc; /I COMMENT or REMOVE the following 4 1lines. // They are here only to force the kernel to build // despite this incomplete sys_fork implementation. (void) *tf (void) *retval;// Remove/comment this line newproc = NULL; // Remove/comment this line ntf NULL /I Remove/comment this line /I Remove/comment this line * The following steps do the following: Copy the trapframe to the heap, because we might return to * userlevel and make another syscall (changing the trapframe) *before the child runs. The child will free the copy /I Use kmalloc to allocate memory (in the heap) for the new trapframe /add code here /I Copy the content of the current trapframe to the new trapframe 2. /add code here ** // Clone the current process /add code here // Set value of retval to the new process' PID /add code here /I Create a new thread based on an existing one result - thread_fork(curthread->t_name, newproc, fork_newthread, ntf, e); if (result) t proc_unfork(newproc); kfree(ntf); return result: return e
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
