CPU-intro

The process

The definition of a process:
it is a running program
But we all know when every time we uesing the desktop or laptop where we might run a web browswer, mail program ,a game ,Wechat and so forth.
At the same time ,a tyical system may be running huandreds of processes.
The crux of the probblem:
How to provide the illusion of many CUPS

Although computer in general are only a few physical CPUS available
How OS provide the illusion of a nearly-endless supply of said CPUS?

The answer is by runnin one process ,then stoping it and running another ,and so forth.(Known as time sharing of the CPU)
Time sharing:https://www.britannica.com/technology/time-sharing

Mechanisms and polices

Mechanisms are low-level methods or protocols that implement a needed piece of functionality,like the time-sharing.
Policies are algorithms for making some kind of decision within the OS.
An important principle of operating system design and implementation is the searation of policies and mechanisms.
So how to comprehend the mechanisms and the policies ?
The mechanism determines the how to do ,whlie the policie determine what to do ?
That’s to say the low-level mechanisms needed to implement processes,and the higher-level polices required to schedule them in an intelligent way.
In many operating systems ,a common design paradigm is to separate high-level policies from their low-level mechanisms.

What constitutes a process

we have to understand its machine state
One obvious component of machine state that comprises a process is its memory.
Also part of the process’s machine state are registers ,many instructions explicitly read or update registers and thus clearly they are important to the execution of the process.

Process API

Here we give some idea if what must be included in any interface of an operating system.

  • Create: An operating system must include some method to crate new processes.When you type a command into the shell,or doubule-click on an applicationg icon, the OS is invoked to create a new process to run the program you have indicated
  • Destroy: As there is an interface for process creationg,systems also provide an interface to destroy processes focefully.Of course,many process will run and just exit by themselves when complete; when they don’t,however,the user may wish to kill them,and thus an interface to halt a runaway process is quite useful.
  • Wait: Sometimes it is useful to wait for a process to stop running;thus some kind of waiting interface is often provided.
  • Status: There are usually interfaces to get some status informationabout a process as well, such as how long it has run for, or what state it is in.

Process Creation : A Little More Detail

The first one , let us look the figure which is about the loading (from program to process)
在这里插入图片描述

Both disk and memory are used for storage,so why do that in the figure?
They are all used for computer storage, but memory is the use of current to achieve storage, and disk is the use of magnetic effects to achieve storage, and, from the perspective of storage capacity, memory is high-speed and high-price, while disk is low-speed and cheap。
What’s more,the CPU can only execute what is in memory.
Now you just need to remember this process.

Process States

a process can be in one of three states:

  • Running: In the running state, a process is running on a processor.This means it is executing instructions.
  • Ready: In the ready state, a process is ready to run but for some reason the OS has chosen not to run it at this given moment.
  • Blocked: In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes place. A common example: when a process initiates an I/O request to a disk, it becomes blocked and thus some other process can use the processor.

Process: State Transitions figure
在这里插入图片描述

Tracing Process State: CPU Only

在这里插入图片描述Tracing Process State: CPU and I/O
在这里插入图片描述
If can’t understand what the above three figures. Look the book “Operating Systems Three Easy Pieces”,I don’t think words are needed to explain it here

Data Structures

The OS is a program, and like any program, it has some key data structures that track various relevant pieces of information.

The xv6 Proc Structure

// 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 !zero, sleeping on chan
int killed; // If !zero, has 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
};

Summary

• The process is the major OS abstraction of a running program. At
any point in time, the process can be described by its state: the contents of memory in its address space, the contents of CPU registers(including the program counter and stack pointer, among others),and information about I/O (such as open files which can be read orwritten).
• The process API consists of calls programs can make related to processes. Typically, this includes creation, destruction, and other useful calls.
• Processes exist in one of many different process states, includingrunning, ready to run, and blocked. Different events (e.g., gettingscheduled or descheduled, or waiting for an I/O to complete) transition a process from one of these states to the other.
• A process list contains information about all processes in the system. Each entry is found in what is sometimes called a processcontrol block (PCB), which is really just a structure that containsinformation about a specific process.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Back~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值