Lab 2 Design Doc
Overview
In-depth Analysis and Implementation
fork (EXAMPLE):
- A new process needs to be created through
kernel/proc.c:proc_init
- Parent must copy its memory to the child via
kernel/mm/vm.c:as_copy_as
- All the opened files must be duplicated in the new process (make sure to call
fs_reopen_file
)
- Create a new thread to run the process and add new process to process table (see example in
proc_spawn
)
- Duplicate current thread (parent process)’s trapframe in the new thread (child process) (recall that assigning one struct to another results in a copy)
- Set up trapframe to return 0 in the child via
kernel/trap.c:tf_set_return
, while returning the child’s pid in the parent
Risk Analysis