OS three easy piece--cpu

program counter PC  用来保存当前什么程序正在运行

stack pointer
frame pointer
两者用来记录栈的地址

程序都是先加载(静态数据和code)然后再跑起来的,有paging和swapping两个概念

heap是会动态增加的

初始化fd


进程有三个状态 running,ready,block
block就是io的时候,io完进入ready

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

这是一个进程的模拟,会有上下文切换

wait本身可以说是等待一个信号

exec是不return的,所有他后面的语句都执行不到

fork和exec是一对,fork是异步的,exec是同步的

shell实际是一个用户态的东西,他fork一下拉一个进程,在进程当中跑一个exec跑一个特定的程序

其实重定向有点类似于open,但是是靠的pipe这个命令,是内核的


操作系统需要对启动的程序施加限制,否则程序可能会访问本不属于他的资源。为了施加这个限制,引入了用户态这个东西
用户态的程序不能随意修改IO

当调用系统调用的时候其实是触发一个trap,而操作系统如何知道这个trap是啥呢?在操作系统启动的时候会维护一个trap table
用户态的代码调用系统调用的时候实际是将一个systemcall number放到寄存器或者stack当中

OS操作了两次LDE,1:在系统启动的时候初始化trap table 2:在程序启动的时候将node加到process list,分配memory

有两种调度方法:1,合作式调度,当系统调用或者出错的时候将控制权交给操作系统
2,非合作方式,操作系统每隔多长时间被唤醒一次,对任务进行调度。开启定时器和cmd table一样是在启动的时候设置的


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值