以下内容算对书内容的总结,有任何问题和见解,欢迎交流啊。
1.Process(进程)是什么?
简单说process就是一个运行的程序。
2.怎么去虚拟出很多CPU?
利用time sharing,让很多的process一个一个的运行。
3.Process的组成部分有哪些?
1.Process对应的内存
2.寄存器
3.I/O
4.Process提供的API
1.create
2.destroy
3.wait
4.Miscellaneous control。比如暂停和恢复。
5.status
5.进程创建的更多内容
1.首先将磁盘上的程序加载到程序中,现代os不会一次性加载所有的代码,而是需要哪些就加载哪些。
2.分配stack内存,并且初始化
3.分配heap内存
4.剩余的一些初始化操作,尤其是I/O相关的。UNUX系统会有默认的三个file description,分别是standard input,output,error。
5.将PC置为main代码出,开始执行。
6.进程状态
Running Reda Block
7.Process 相关的数据结构
// the registers xv6 will save and restore
// to stop and subsequently restart a process
struct context {
int eip;
int esp;
int ebx;
int ecx;
int edx;
int esi;
int edi;
int ebp;
};
// the different states a process can be in
enum proc_state { UNUSED, EMBRYO, SLEEPING,
RUNNABLE, RUNNING, ZOMBIE };
// the information xv6 tracks about each process
// including its register context and state
struct proc {
char *mem; // Start of process memory
uint sz; // Size of process memory
char *kstack; // Bottom of kernel stack
// for this process
enum proc_state state; // Process state
int pid; // Process ID
struct proc *parent; // Parent process
void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed
struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory
struct context context; // Switch here to run process
struct trapframe *tf; // Trap frame for the
// current interrupt
};