博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OS Review Chapter 4: Process
阅读量:3948 次
发布时间:2019-05-24

本文共 2918 字,大约阅读时间需要 9 分钟。

Chapter 4: Processes

引入进程–>描述CPU的活动–>研究CPU的活动–>提高CPU的利用率

What is a Process–>程序的一次执行过程

Process – a program in execution; process execution must progress in sequential fashion.

A process includes:

program counter 程序执行到哪一步了

contents of the processor’s registers状态

stack 局部变量

data section全局变量

Process in Memory 进程空间

在这里插入图片描述

text:程序(二进制)

heap:动态分配的内存

Process State (进程的生命周期)

在这里插入图片描述

Process Control Block (PCB)

PCB放在内存的内核段中

PCB存储的地方:内存 内核段

Information associated with each process:

Process state

Program counter 程序运行到哪 (context)

CPU registers (context

CPU scheduling information

Memory-management information 程序访问的相关地址

Accounting information 审计CPU时间

I/O status information

在这里插入图片描述

Process Scheduling Queues

Job queue – set of all processes in the system.

Ready queue – set of all processes residing in main memory, ready and waiting to execute.所有能在CPu上执行的进程,被调度器调度的进程

Device queues – set of processes waiting for an I/O device.处于waiting状态的 进程

Process migration between the various queues.

在这里插入图片描述

Schedulers

Long-term scheduler (or job scheduler) – selects which processes should be loaded into memory for execution. 决定进入队列的进程 (may be slow)The long-term scheduler controls the degree of multiprogramming.

Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU. 决定CPU执行的进程 (must be fast).

Processes can be described as either:

  • I/O-bound process
  • CPU-bound process

Context Switch

What is a process context?

The context of a process includes the values of CPU registers, the process state, the program counter, and other memory/file management information.

After the CPU scheduler selects a process (from the ready queue) and before allocates CPU to it, the CPU scheduler must :

  • save the context of the currently running process
  • put it into a queue
  • load the context of the selected process
  • let it run

Operations on Processes

Process Creation

Parent process create children processes, which, in turn create other processes, forming a tree of processes.

  • Resource sharing
  • Execution
  • Address space 子进程和父进程的地址空间不一样

在这里插入图片描述

在这里插入图片描述

#include 
#include
#include
int main(int argc,char *argv[]){
int i,id1,id2; for(i=1;i<2;i++) {
id1=fork(); id2=fork(); if(id1==0||id2==0) fork(); } printf(" I am %d\n",getpid());}
I am 3696 I am 3697 I am 3698 I am 3699 I am 3701 I am 3702 I am 3700

Process Termination

Process executes last statement and asks the operating system to delete it (exit).

  • Output data from child to parent (via wait).
  • Process’ resources are deallocated by OS.

Parent may terminate execution of children processes (abort).

  • Child has exceeded allocated resources.
  • Task assigned to child is no longer required.
  • Parent is exiting. (Operating system does not allow child to continue if its parent terminates)

Cooperating Processes

Advantages of process cooperation :

◆Information sharing

◆Computation speed-up

◆Modularity

◆Convenience

Producer-Consumer Problem

Context

转载地址:http://algwi.baihongyu.com/

你可能感兴趣的文章
最长子序列长度 (动态规划 O(N^2))
查看>>
最长子序列长度 (贪心+二分 O( Nlog(N) ))
查看>>
数塔 HDU - 2084 (简单的dp)
查看>>
超级楼梯 HDU - 2041 ( 简单的dp )
查看>>
Piggy-Bank HDU - 1114 ( 完全背包 )
查看>>
Knapsack problem FZU - 2214 ( 01背包 )
查看>>
Bone Collector HDU - 2602 ( 01背包 )
查看>>
背包问题 V2 51Nod - 1806 ( 多重背包 )
查看>>
最少拦截系统 HDU - 1257 ( 动态规划 )
查看>>
瞌睡 (网易笔试题)
查看>>
分苹果 (网易笔试题)
查看>>
已知前序遍历和中序遍历求二叉树
查看>>
已知后序遍历和中序遍历求二叉树
查看>>
使用最小花费爬楼梯 (LeetCode - 746)
查看>>
勾股数 (迅雷笔试题)
查看>>
平安夜杀手 (科大讯飞笔试题)
查看>>
计算器 (贝壳笔试题)
查看>>
Prime Path POJ - 3126 ( 素数+搜索)
查看>>
迷宫问题 POJ - 3984 ( 搜索 最短路 记录路径 )
查看>>
全排列 51Nod - 1384 ( 搜索dfs / STL - next_permutation函数 )
查看>>