cs / operating-systems
lec16-managing_multiple_address_spaces
process creation
一个 process 对应了一个 address space.
我们创建 process (several threads) 的同时, 还要创造它的 address space
Steps:
- allocate process control block (like TCB)
- initialize translation data for new address space (page table)
- 从 exe 中把 program image 读进 memory 里
- 创建 initial thread
- initialize registers
- 把 mode bit 设为 "user"
- jump to start of program
physical memory 相当于 cache for address spaces,
while (true) {
cout << "shellname$";
cin >> cmd;
parse cmd => (program, args);
if (fork() == 0) {
find(progarm) in $PATH;
exec(program);
} else { //if it is the parent process
wait for child; // wait / also can just do nothing, for the cpu can run other threads
}
}