操作系统02进程管理Process_Description_and_Control

作业的基本概念:用户再一次计算过程中或一次事务处理过程中,要求计算机系统所做的工作的集合。

包含多个程序、多个数据、作业控制说明书


系统调用时操作系统提供给编程人员的唯一接口。

1、文件操作类;

2、进程控制类;

3、资源申请类;

4、进程通信类;

5、信息维护类  用户程序和操作系统间传递信息,如获得时间。


作业调度算法:

先来先服务

最短作业优先

响应比高优先    响应比=(等待时间+计算时间)/ 计算时间

优先级

分类调度算法    根据系统运行情况和作业属性将作业分类,如CPU tense / IO tense


作业调度 --> 进程 --> 处理机调度


————————————————————————————————————————————————————————————


OS:

>进程管理子系统 CPU

>存储管理子系统 Memory

>IO设备子系统 IO Devices

>文件管理子系统 File

 

进程是一个程序对某个数据集的一次运行活动;资源分配单位。

特征:动态、并发、独立、异步

结构

程序段 Code Segment

数据段 Data Segment

进程控制块 Process Control Block PCB

 

线程是进程内一个相对独立的,可调度的执行单元;不再分配资源。

 

————————————————————————————————————————————————————————————


Process and Scheduling 进程与调度

基础:进程描述及控制

实现:同步与互斥

避免:死锁与饥饿

解决:几个经典问题:生产者--消费者  读者--写者  哲学家进餐

关于:进程通信

策略:进程调度

 

Process Description and Control

PCB Process Control Block 一种数据结构

OS目标:高利用率、高效率。

程序的顺序执行:顺序性 封闭性 可再现性

程序的并发执行:间断性 非封闭性 不可再现性

程序并发执行的条件(Bernstein条件):


进程是程序在一个数据集合上的运行过程,是系统进行资源分配和调度的一个独立单位。

进程是可并发执行的程序在一个数据集合上的运行过程。

特点:动态性、并发性、独立性、异步性。

 

Process Structure

·Programs

·Data

·PCB  (Process Control Block)

 

Dispatcher = Scheduler

调度程序

 

进程状态转换:

Two-State Process Model

>Running

>Not-running

--Ready

--Blocked

 

  

Five-State Model

Running:占用处理机

Ready:准备执行

Blocked:等待某事件发生才能执行

New:进程已经创建,但OS未接纳

Exit:因停止或取消,被OS释放


 

Using Two Queues




Seven-State Model

Swapping 对换技术,交换技术

将进程的数据、程序

内存 Swapping Out 外存    Suspended Processes(挂起)

外存 Swapping In 内存

 

·Processor is faster than IO so all processes could be waiting for IO.

·Swap these processes to disk to free up more memory.

·Blocked state becomes suspend state when swapped to disk.

 

四种状态组合:

Ready

Blocked

Ready, suspend

Blocked, suspend

 

处理机可调度两种进程:

新创建的进程 <--- 其次

换入一个以前挂起的进程 <-- 优先

 

One suspend state

  


Two suspend state

 


Process Description

OS 如何感知进程、控制进程及其所用的系统资源?

图:

 

 

 

Operating System Control Structures

·Information about the current states of each process and resource.

·Tables are constructed for each entity the operating system manages.

---Memory Tables

---IO Tables

---File Tables

---Process Table



Memory Tables:

·Allocation of main memory to processes

·Allocation of secondary memory to processes

·Protection attributes for access to shared memory regions

·Information needed to manage virtual memory


IO Tables:

·IO device is available or assigned

·Location in main memory being used as the source or destination of the IO transfer

 

File Table:

·Existence of files

·Location on secondary memory

·Current states

·Attributes

·Sometimes this information is maintained by a file-management system

 

Process Table:

·Where process is located

·Attributes necessary for its management

---Process ID

---Process state

---Location in memory

 

Process Location:

·Process includes set of programs to be executed

    ---Data location for local and global variables

    ---Any defined constants

    ---Stack

·Process Control Block (PCB)

    ---Collection of attributes

·Process Image (进程映像)

    ---Collection of programs, data, stack and attributes

 

Process Image:

·User Data

·User Programs

·System Stack 存放系统及进程调用地址参数

·Process Control Block (PCB)  OS感知进程,控制进程的数据结构

 

Process Control Block

PCB:是OS控制和管理进程时所用的基本数据结构

作用:PCB是相关进程存在于系统中的唯一标志,系统根据PCB而感知相关进程的存在。

包括:

Process Identification

Processor State Information

Process Controlled Information

 

Process Identification

---Identifiers

·Identifier of this process (进程ID)

·Identifier of the process that created this process (parent process 父进程ID)

·User Identifier (用户ID)


Processor State Information:

---User-Visible Registers

·A user-visible register is one that be referenced by means of the machine language that the processor executes.

·Typically, there are from 8 to 32 of these registers, although some RISC(reduce instruction set computer) implementations have over 100.

---Control and Status Registers

There are a variety of processor registers that are employed to control the operation of processor.

These include

·Program Counter: contains the address of the next instruction to be fetched.

·Condition Codes: result of he most recent arithmetic or logical operation

(e.g. Sign, zero, carry, equal, overflow)

·Status Information: Includes interrupt enable/disable flags, execution mode.

---Stack Pointers

·Each process has one or more last-in-first-out(LIFO) system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system call.

 

Process Controlled Information

---Scheduling and State Information

·Process state: defines the readiness of the process to be scheduled for execution (e.g. Running Ready Waiting Halted).

·Priority: one or more fields may be used to describe the scheduling priority of the process.

·Scheduling-related information: this will depend on the scheduling algorithm used.

·Event: Identity of event the process is awaiting before it can be resumed.

---Data Structuring

·A process may be linked to other process in a queue, or some other structures.

·A process may exhibit a parent-child (creator-created) relationship with another process.

·The process control block may contain pointers to other process to support the structures.

---Inter-Process Communication

·Various flags, signals, and messages may be associated with communication between two independent processes.

---Process Privileges

·Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed.

---Memory Management

·This section may include pointers to segments and/or page tables that describe the virtual memory assigned.

---Resource Ownership and Utilization

·Resource controlled by the process may be indicated, such as opened files.

·A history of utilization of the processor or other resources may also be includes: this information may be needed by the scheduler.



PCB组成若干链表,存放在OS中专门开辟的PCB区内。

PCB可以被操作系统多个模块读或修改。

如调度程序、资源分配程序、中断处理程序、监督分析程序。

 


——————————————————————————————————————————————————————————————————————————

内核与硬件相关,是在硬件上的第一层扩充。

Typical Function of an OS kernel

资源管理功能

·Process Management:进程创建和终止、调度、状态转换、同步和通信、管理PCB

·Memory Management:为进程分配地址空间、对象、段页管理

·IO Management:缓存管理、为进程分配IO通道和设备

支撑功能

·Interrupt Handling (中断处理)

·Timing (时钟管理)

·Primitive (原语)  Atomic Operation        若干条机器指令构成,要么不做,要么全做。

·Accounting (统计)

·Monitoring (监测)

 

Process Control Primitive (原语)

·Process Switch 进程切换

·Create and Terminate 创建与终止

·Block and Wake-up 阻塞与唤醒

·Suspend and Activate 挂起与激活

 

When to switch a process

·clock interrupt

---process has executed for the maximum allowable time slice.

·IO interrupt

·Memory fault (存储访问失效--基于虚拟存储)

---Memory address is in virtual memory so it must be brought into main memory.

·Trap (陷阱)

---error occurred.

---may cause process to be moved to Exit State

·Supervisor Call (管理程序调入)

---such as file open.

 

 

Change of Process State

·Save context of processor including program counter and other registers.

·Update the PCB of the process that is currently running.

·Move PCB to appropriate queue---ready, blocked,...

·Select another process for execution.

·Update the PCB of the process selected.

·Update memory--management data structures.

·Restore context of the selected process.

 

Process Switching V.S. Mode Switching

·Process Switching:作用于进程之间的一种操作,当分派程序收回当前进程的CPU并准备把它分派给某个就绪进程时,该操作将被引用。

·Mode Switching:进程内部所引用的一种操作,当进程映像所包含的程序引用核心子系统所提供的系统调用时,该操作将被引用。 用户态  核心态 的相互转换。

 

Process Switching 一定有 Mode Switching

Mode Switching 不一定有 Process Switching

 

 

Process Creation

·Submission of a batch job.

·User logs on.

·Created to provide a service such as printing.

·Process create another process.

 

Create()原语,步骤

1、为进程分配一个唯一标识号ID:主进程表中增加一个新的表项。

2、为进程分配空间:用户地址空间、用户栈空间、PCB空间,若共享已有空间,则应建立相应的链接。

3、初始化PCB:进程标识、处理机状态信息、进程状态。

4、建立链接:若调度队列是链表,则将新进程插入到就绪或就绪、挂起链表。

5、建立或扩展其他数据结构

 

Destroy()原语,步骤

1、根据被终止的标识符ID,找到PCB,读出该进程的状态。

2、若该进程为执行状态,则终止其执行,调度新进程执行。

3、若该进程有子孙进程,则立即终止其所有子孙进程。

4、将该进程的所有资源,或归还给其父进程,或归还给系统。

5、将被终止进程的PCB从所在队列中移出,等待其他程序来搜集信息。

 


Process Termination

·Batch job issues Halt instruction.

·User logs off.

·Quit an application.

·Error and fault conditions:

·Normal completion 正常结束

·Time limit exceeded 超时终止,执行时间超过预计时间

·Memory unavailable 内存不足,无法为进程分配所需大的内存空间

·Bounds violation 越界访问

·Protection error 企图使用未允许使用的数据,或操作方式错误

·Arithmetic error 计算错误,如除零,或企图存储硬件允许的最大值

·Time overflow 超时等待某事件发生

·IO failure 如 找不到文件 或 多次重试仍无法读写文件 或 无效操作

·Invalid instruction 企图执行不存在的指令

·Privileged instruction 企图执行特权指令

·Data misuse 数据类型不符 或 未初始化

·Operating System intervention 操作员或OS干预,如死锁时

·Parent terminates so child processes terminate

·Parent request

 

 

Process Block and Wake-up

阻塞原因

·请求系统服务

·启动某种操作,如IO

·新数据尚未到达  A产生数据,B处理数据

·无新工作可做

 

阻塞原语 block()

当出现阻塞事件,进程调用阻塞原语将自己阻塞(高风亮节),状态变为“阻塞状态”,并进入相应事件的阻塞队列。

 

唤醒原语 wake-up()

当阻塞进程期待的事件发生,有关进程调用唤醒原语,将等待该事件的进程唤醒,状态变为ready,插入就绪队列。

 

 

Process Suspend and Active

挂起原语 suspend()

当出现挂起事件,系统利用挂起原语将指定进程或阻塞状态进程挂起,进程从内存换到外存,插入相应队列。

Ready --> Ready, Suspend

Blocked --> Blocked, Suspend

激活原语 active()

当激活事件发生,系统利用激活原语将指定进程激活,进程从外存换到内存,插入相应队列。

Ready, Suspend --> Ready

Blocked, Suspend --> Blocked

 ———————————————————————————————————————————————————————————————————————————

 

进程:多个程序并发以提高资源利用率及系统吞吐量

线程:减少程序并发时的时间开销,使OS具有更好的并发性。


Thread (线程)

·An execution state (running, ready, etc.).

·Saved thread context when not running.

·Has an execution stack.

·Some per-thread static storage for local variables.

·Access to the memory and resources of its process--all threads of a process share this.

 


Benefits of Threads

·Take less time to create a new thread than a process.

·Less time to terminate a thread than a process.

·Less time to switch between two threads within the same process.

·Since threads with the same process share memory and files, they can communicate with each other without invoking the kernel.

·Suspending a process involves suspending all threads of the process--since all threads share the same address space.

·Termination of a process, terminates all threads within the process.

 

Multi-threading

·Operating system supports multiple threads of execution with in a single process.

·MS-DOS support a single thread.

·UNIX supports multiple user processes, but only supports one thread per process.

主要用于服务器,多用户,多进程系统。

·Windows Linux  PC机,多用户,多任务(线程),多进程多线程系统。

·Windows Solaris Linux Mach OS/2 support multiple threads.



Tread States

·Key states for a thread: Running, Ready, Blocked.

·Operations associated with a change in thread state

--Spawn(派生),spawn another thread

--Block

--Unblock

--Finish


 

进程:资源拥有的基本单位

线程:调度和控制的基本单位

线程切换只需保存和设置少量寄存器的内容。


User--Level Threads

·All thread management is done by application.

·The kernel is not aware of the existence of threads.

描述此类线程的数据结构以及控制此类线程的原语在核外子系统中实现。


Kernel--Level Threads

·W2K, Linux and OS/2 are examples of this approach.

·Kernel maintains context information for the process and the threads.

·Scheduling is done on a thread basis.

描述此类线程的数据结构以及控制此类线程的原语在核心子系统中实现。

 

Combined Approaches

·Example is Solaris --> Sun 工作站

·Thread creation done in the user space.

·Bulk of scheduling and synchronization of threads done in the user space.

Relationship between Threads and Processes

 

用户级线程切换速度快,内核级线程,系统调用时,可运行同进程内的其他线程。


Thread:Process = 1:1

Description: Each thread of execution is a unique process with its own address space and resources.

Example Systems: Traditional UNIX implementations.

 

Thread:Process = M:1

Description: A process defines an address space and dynamic resource ownership.

  Multiple threads may be created and executed within that process.

Example Systems: Windows NT  Linux  Solaris  OS/2  OS/390  MACH

 

Thread:Process = 1:M

Description: A thread may migrate from one process environment in another.

  This allows thread to be easily moved among distinct system.

Example Systems: Ra(clouds)  Emerald

 

Thread:Process = M:M

Description: Combines attributes of M:1 and 1:M cases.

Example Systems: TRIX




本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/387231.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

蓝桥杯 方格填数(全排列+图形补齐)

方格填数 如下的10个格子 填入0~9的数字&#xff0c;同一数字不能重复填。要求&#xff1a;连续的两个数字不能相邻。&#xff08;左右、上下、对角都算相邻&#xff09; 一共有多少种可能的填数方案&#xff1f; 请填写表示方案数目的整数。注意&#xff1a;你提交的应该是一个…

操作系统03进程管理Process_Scheduling

2 Process Scheduling >Type of scheduling >Scheduling Criteria (准则) >Scheduling Algorithm >Real-Time Scheduling (嵌入式系统) 2.1 Learning Objectives By the end of this lecture you should be able to Explain what is Response Time 响应时间-…

skimage库需要依赖 numpy+mkl 和scipy

skimage库需要依赖 numpymkl 和scipy1、打开运行&#xff0c;输入cmd回车&#xff0c;输入python回车&#xff0c;查看python版本2、在https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy 中&#xff0c;根据自己python版本下载需要的包 &#xff08;因为我的是python 2.7.13 …

操作系统04进程同步与通信

4.1 进程间的相互作用 4.1.1 进程间的联系资源共享关系相互合作关系临界资源应互斥访问。临界区&#xff1a;不论是硬件临界资源&#xff0c;还是软件临界资源&#xff0c;多个进程必须互斥地对它们进行访问。把在每个进程中访问临界资源的那段代码称为临界资源区。显然&#x…

oracle迁移到greenplum的方案

oracle数据库是一种关系型数据库管理系统&#xff0c;在数据库领域一直处于领先的地位&#xff0c;适合于大型项目的开发&#xff1b;银行、电信、电商、金融等各领域都大量使用Oracle数据库。 greenplum是一款开源的分布式数据库存储解决方案&#xff0c;主要关注数据仓库和BI…

CNN框架的搭建及各个参数的调节

本文代码下载地址&#xff1a;我的github本文主要讲解将CNN应用于人脸识别的流程&#xff0c;程序基于PythonnumpytheanoPIL开发&#xff0c;采用类似LeNet5的CNN模型&#xff0c;应用于olivettifaces人脸数据库&#xff0c;实现人脸识别的功能&#xff0c;模型的误差降到了5%以…

操作系统05死锁

进程管理4--Deadlock and Starvation Concurrency: Deadlock and Starvation 内容提要 >产生死锁与饥饿的原因 >解决死锁的方法 >死锁/同步的经典问题&#xff1a;哲学家进餐问题 Deadlock 系统的一种随机性错误 Permanent blocking of a set of processes that eith…

CNN tensorflow 人脸识别

数据材料这是一个小型的人脸数据库&#xff0c;一共有40个人&#xff0c;每个人有10张照片作为样本数据。这些图片都是黑白照片&#xff0c;意味着这些图片都只有灰度0-255&#xff0c;没有rgb三通道。于是我们需要对这张大图片切分成一个个的小脸。整张图片大小是1190 942&am…

数据结构01绪论

第一章绪论 1.1 什么是数据结构 数据结构是一门研究非数值计算的程序设计问题中&#xff0c;计算机的操作对象以及他们之间的关系和操作的学科。 面向过程程序数据结构算法 数据结构是介于数学、计算机硬件、计算机软件三者之间的一门核心课程。 数据结构是程序设计、编译…

css3动画、2D与3D效果

1.兼容性 css3针对同一样式在不同浏览器的兼容 需要在样式属性前加上内核前缀&#xff1b; 谷歌&#xff08;chrome&#xff09; -webkit-transition: Opera&#xff08;欧鹏&#xff09; -o-transition: Firefox&#xff08;火狐&#xff09; -moz-transition Ie -ms-tr…

数据结构02线性表

第二章 线性表 C中STL顺序表&#xff1a;vector http://blog.csdn.net/weixin_37289816/article/details/54710677链表&#xff1a;list http://blog.csdn.net/weixin_37289816/article/details/54773406在数据元素的非空有限集中&#xff1a; (1)存在唯一一个被称作“第…

训练一个神经网络 能让她认得我

写个神经网络&#xff0c;让她认得我(๑•ᴗ•๑)(Tensorflow,opencv,dlib,cnn,人脸识别) 这段时间正在学习tensorflow的卷积神经网络部分&#xff0c;为了对卷积神经网络能够有一个更深的了解&#xff0c;自己动手实现一个例程是比较好的方式&#xff0c;所以就选了一个这样比…

数据结构03栈和队列

第三章栈和队列 STL栈&#xff1a;stack http://blog.csdn.net/weixin_37289816/article/details/54773495队列&#xff1a;queue http://blog.csdn.net/weixin_37289816/article/details/54773581priority_queue http://blog.csdn.net/weixin_37289816/article/details/5477…

树莓派pwm驱动好盈电调及伺服电机

本文讲述如何通过树莓派的硬件PWM控制好盈电调来驱动RC车子的前进后退&#xff0c;以及如何驱动伺服电机来控制车子转向。 1. 好盈电调简介 车子上的电调型号为&#xff1a;WP-10BLS-A-RTR&#xff0c;在好盈官网并没有搜到对应手册&#xff0c;但找到一份通用RC竞速车的电调使…

数据结构04串

第四章 串 STL&#xff1a;string http://blog.csdn.net/weixin_37289816/article/details/54716009计算机上非数值处理的对象基本上是字符串数据。 在不同类型的应用中&#xff0c;字符串具有不同的特点&#xff0c;要有效的实现字符串的处理&#xff0c;必须选用合适的存储…

CAS单点登录原理解析

CAS单点登录原理解析 SSO英文全称Single Sign On&#xff0c;单点登录。SSO是在多个应用系统中&#xff0c;用户只需要登录一次就可以访问所有相互信任的应用系统。CAS是一种基于http协议的B/S应用系统单点登录实现方案&#xff0c;认识CAS之前首先要熟悉http协议、Session与Co…

数据结构05数组和广义表

第五章 数组 和 广义表 数组和广义表可以看成是线性表在下述含义上的扩展&#xff1a;表中的数据元素本身也是一个数据结构。 5.1 数组的定义 n维数组中每个元素都受着n个关系的约束&#xff0c;每个元素都有一个直接后继元素。 可以把二维数组看成是这样一个定长线性表&…

数据结构06树和二叉树

第六章 树和二叉树 6.1 树的定义和基本术语 树 Tree 是n个结点的有限集。 任意一棵非空树中&#xff1a; &#xff08;1&#xff09;有且仅有一个特定的称为根&#xff08;root&#xff09;的结点&#xff1b; &#xff08;2&#xff09;当n>1时&#xff0c;其余结点可…

CountDownLatch,CyclicBarrier和Semaphore

在java 1.5中&#xff0c;提供了一些非常有用的辅助类来帮助我们进行并发编程&#xff0c;比如CountDownLatch&#xff0c;CyclicBarrier和Semaphore&#xff0c;今天我们就来学习一下这三个辅助类的用法。以下是本文目录大纲&#xff1a;一.CountDownLatch用法二.CyclicBarrie…

数据结构07排序

第十章内部排序 10.1 概述 排序就是把一组数据按关键字的大小有规律地排列。经过排序的数据更易于查找。 排序前KiKj&#xff0c;且Ki在前: 排序方法是稳定的&#xff0c;若排序后Ki在前&#xff1b; 排序方法是不稳定的&#xff0c;如排序后Kj在前。 分类&#xff1a; 内…