Three easy pieces 第一部分(2) The Abstraction: The Process

以下内容算对书内容的总结,有任何问题和见解,欢迎交流啊。

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
};



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值