Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Process Description and Control

Similar presentations


Presentation on theme: "Chapter 3 Process Description and Control"— Presentation transcript:

1 Chapter 3 Process Description and Control
Operating System Chapter 3 Process Description and Control

2 Chap3 Process Description and Control
3.1 What is a Process 3.2 Process States 3.3 Process Description 3.4 Process Control 3.5 Execution of the Operating System

3 3.1 What is a Process 3.1.1 Background 3.1.2 Processes and PCBs

4 3.1.1 Background(1/1) Requirements of an Operating System
Interleave(交替) the execution of multiple jobs/tasks/道/programs/processes to maximize processor utilization while providing reasonable response time(响应 时间) Allocate resources to processes Support interprocess communication(进程 间通信) and user creation of processes

5 3.1 What is a Process 3.1.1 Background 3.1.2 Processes and PCBs

6 3.1.2 Processes and PCBs(1/4) A program in execution
An instance of a program running on a computer The entity that can be assigned to and executed on a processor A unit of activity characterized by: the execution of a sequence of instructions a current state an associated set of system resources ......

7 3.1.2 Processes and PCBs(2/4) (Review) Process构成:Consists of three components An executable program /code Associated data needed by the program Execution context of the program (the core) All information the operating system needs to manage the process Hardware Software

8 3.1.2 Processes and PCBs(3/4) Process Elements Identifier State
Priority Program counter Memory pointers Context data I/O status information Accounting information

9 3.1.2 Processes and PCBs(4/4) Process Control Block(进程控制块 PCB)
Contains the process elements Created and manage by the operating system Allows support for multiple processes 进程控制块-PCB,又称进程描述符或进程属性 操作用于管理控制进程的一个专门的数据结构 记录进程的各种属性,描述进程的动态变化过程 PCB是系统感知进程存在的唯一标志:进程与PCB一一对应

10 Chap3 Process Description and Control
3.1 What is a Process 3.2 Process States 3.3 Process Description 3.4 Process Control 3.5 Execution of the Operating System

11 3.2 Process States 3.2.1 Trace of the Process
3.2.2 A Two-State Process Model 3.2.3 The Creation and Termination of Processes 3.2.4 A Five-State Model 3.2.5 Suspended Process

12 3.2.1 Trace of the Process(1/4)
Trace of Process(进程轨迹) Sequence of instruction that execute for a process Dispatcher(调度器) switches the processor from one process to another

13 3.2.1 Trace of the Process(2/4)
Example Execution

14 3.2.1 Trace of the Process(3/4)

15 3.2.1 Trace of the Process(4/4)

16 3.2 Process States 3.2.1 Trace of the Process
3.2.2 A Two-State Process Model 3.2.3 The Creation and Termination of Processes 3.2.4 A Five-State Model 3.2.5 Suspended Process

17 3.2.2 A Two-State Process Model(1/2)
两状态进程模型 Process may be in one of two states Running Not-running 进程退出,正常-老死,非正常-病死,父进程-他杀

18 3.2.2 A Two-State Process Model(2/2)
Not-Running Process in a Queue Queue里装的是什么? Queue怎么实现? d指向进程块的指针

19 3.2 Process States 3.2.1 Trace of the Process
3.2.2 A Two-State Process Model 3.2.3 The Creation and Termination of Processes 3.2.4 A Five-State Model 3.2.5 Suspended Process

20 3.2.3 The Creation and Termination of Processes(1/3)
Process Creation page113 process spawning 进程派生

21 3.2.3 The Creation and Termination of Processes(2/3)
Process Termination

22 3.2.3 The Creation and Termination of Processes(3/3)
Process Termination

23 3.2 Process States 3.2.1 Trace of the Process
3.2.2 A Two-State Process Model 3.2.3 The Creation and Termination of Processes 3.2.4 A Five-State Model 3.2.5 Suspended Process

24 3.2.4 A Five-State Model(1/6) Limit of Two-State Process Model
Not-running ready to execute waiting for I/O (blocked) Dispatcher cannot just select the process that has been in the queue the longest because it may be blocked

25 3.2.4 A Five-State Model(2/6) Process State New(新建态) Ready(就绪态)
Running(运行态) Blocked(阻塞态) Exit(退出态) runing:占用处理机(单处理机环境中,某一时刻仅一个进程占用处理机) ready:准备执行 blocked:等待某事件发生才能执行,如等待I/O完成等 new:进程已经创建,但未被OS接纳为可执行进程,并且程序还在辅存,PCB在内存 exit:因停止或取消,被OS从执行状态释放

26 3.2.4 A Five-State Model(3/6)

27 3.2.4 A Five-State Model(4/6)

28 3.2.4 A Five-State Model(5/6) Using Two Queues

29 3.2.4 A Five-State Model(6/6) Multiple Blocked Queues

30 3.2 Process States 3.2.1 Trace of the Process
3.2.2 A Two-State Process Model 3.2.3 The Creation and Termination of Processes 3.2.4 A Five-State Model 3.2.5 Suspended Process

31 3.2.5 Suspended Process(1/4) 被挂起的进程 Why? How? Result?
Processor is faster than I/O so all processes could be waiting for I/O How? Swap these processes to disk to free up more memory Result? Blocked state becomes suspend state when swapped to disk

32 3.2.5 Suspended Process(2/4)

33 3.2.5 Suspended Process(3/4) Two new states Blocked/Suspend
Ready/Suspend

34 3.2.5 Suspended Process(4/4) Reasons for Process Suspension

35 Chap3 Process Description and Control
3.1 What is a Process 3.2 Process States 3.3 Process Description 3.4 Process Control 3.5 Execution of the Operating System

36 3.3 Process Description 3.3.1 Processes and Resources
3.3.2 OS Control Structures 3.3.3 Process Control Structures

37 3.3.1 Processes and Resources(1/2)

38 3.3.1 Processes and Resources(2/2)

39 3.3 Process Description 3.3.1 Processes and Resources
3.3.2 OS Control Structures 3.3.3 Process Control Structures

40 3.3.2 OS Control Structures(1/6)
OS Control Tables Process table Memory tables I/O tables File tables 操作系统为了管理进程和资源,需要构造和维护的信息表有四种不同类型:内存、I/O、文件和进程。 Tables are constructed for each entity the operating system manages (操作系统构造并维护他所管理的所有实体的信息表)

41 3.3.2 OS Control Structures(2/6)
Process table Every entry is a PCB(description of a process image) 进程表:所有进程的PCB集合。 进程表的大小往往固定,这也决定了一个操作系统最多支持多少个进程,有时我们称为系统支持的并发度 进程表中包含:Information about the current status of each process and resource (每个进程和资源的当前状态) 进程映像也称进程图像,是进程执行的上下文环境,包括处理机中各通用寄存器的值,进程的内存映像,打开文件的状态和进程占用资源的信息等。它是一个内存级的实体,并由:进程控制块(PCB)、进程执行的程序(code) / 程序、进程执行时所用的数据 / 数据集合、进程执行时使用的工作区组成。

42 3.3.2 OS Control Structures(3/6)
Process Image A process image is just a process's allocated space in virtual memory Collection of program, data, stack, attributes

43 3.3.2 OS Control Structures(3/6)
Process Image (P132)

44 3.3.2 OS Control Structures(4/6)
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(虚拟内存的管理信息)

45 3.3.2 OS Control Structures(5/6)
I/O Tables I/O device is available or assigned(分配状态) Status of I/O operation Location in main memory being used as the source or destination of the I/O transfer (数 据传送的源和目的地址)

46 3.3.2 OS Control Structures(6/6)
File Tables Existence of files Location on secondary memory Current Status Attributes

47 3.3 Process Description 3.3.1 Processes and Resources
3.3.2 Operating System Control Structures 3.3.3 Process Control Structures

48 3.3.3 Process Control Structures(1/10)
Process Control Block Process Identification Processor State Information User-Visible Registers Control and Status Registers Stack Pointers Process Control information Scheduling and State Information Data Structuring (link information) Interprocess Communication Process Privileges Memory Management Resource Ownership and Utilization

49 3.3.3 Process Control Structures(2/10)
Process identification Process Identifiers(标志号) Numeric identifiers that may be stored with the process control block include Identifier of this process (进程标志) Identifier of the process that created this process (父进程标志) User identifier(用户标志)

50 3.3.3 Process Control Structures(3/10)
Processor State Information User-Visible Registers A user-visible register is one that may be referenced by means of the machine language that the processor executes while in user mode. Typically, there are from 8 to 32 of these registers, although some RISC implementations have over 100.

51 3.3.3 Process Control Structures(4/10)
Processor State Information Control and Status Registers:These are a variety of processor registers that are employed to control the operation of the processor. These include Program counter: Contains the address of the next instruction to be fetched Condition codes: Result of the most recent arithmetic or logical operation (e.g., sign, zero, carry, equal, overflow) Status information: Includes interrupt enabled/disabled flags, execution mode

52 3.3.3 Process Control Structures(5/10)
Processor State Information 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 calls(活动记录). The stack pointer(栈指针) points to the top of the stack. The frame pointer(帧指针) points to the start of an active record on the stack.

53 3.3.3 Process Control Structures(6/10)
Process Control 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. In some systems, several values are required (e.g., default, current, highest-allowable) Scheduling-related information: This will depend on the scheduling algorithm used. (e.g., waiting time, running time. Event: Identity of event the process is awaiting before it can be resumed

54 3.3.3 Process Control Structures(7/10)
Process Control Information Data Structuring A process may be linked to other process in a queue, ring, or some other structure. For example: all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator- created) relationship with another process. The process control block may contain pointers to other processes to support these structures.

55 3.3.3 Process Control Structures(8/10)
Process Control Information Interprocess Communication Flags(标志) Signals(信号) Messages(消息) Process Privileges Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed. In addition, privileges may apply to the use of system utilities and services.

56 3.3.3 Process Control Structures(9/10)
Process Control Information Memory Management This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process. Resource Ownership and Utilization Resources controlled by the process may be indicated, such as opened files. A history of utilization of the processor or other resources may also be included This information may be needed by the scheduler.

57 3.3.3 Process Control Structures(10/10)
PCB of Linux 结构体:task_struct Digging Deeper /usr/src/…/include/linux/sched.h Reference:

58 Chap3 Process Description and Control
3.1 What is a Process 3.2 Process States 3.3 Process Description 3.4 Process Control 3.5 Execution of the Operating System

59 3.4 Process Control 3.4.1 Modes of Execution 3.4.2 Process Creation
3.4.3 Process Switching

60 3.4.1 Modes of Execution(1/1) User mode
Less-privileged mode User programs typically execute in this mode System mode, control mode, or kernel mode More-privileged mode Kernel of the operating system Translation between the two model Processor status register (psr) and current privileged level (cpl) User mode->System mode System mode->User mode Certain instructions can only be executed in the more-privileged mode. These would include reading or altering a control register, such as the program status word; primitive I/O instructions; and instructions that relate to memory management. In addition, certain regions of memory can only be accessed in the more-privileged mode.

61 3.4 Process Control 3.4.1 Modes of Execution 3.4.2 Process Creation
3.4.3 Process Switching 3.4.4 Execution of the Operating System

62 3.4.2 Process Creation(1/3) Assign a unique process identifier
Allocate space for the process Initialize process control block Set up appropriate linkages Ex: add new process to linked list used for scheduling queue Create of expand other data structures Ex: maintain an accounting file

63 3.4.2 Process Creation(2/3) Process tree for a Linux system
Processes may create other processes through appropriate system calls, such as fork Init is the root/parent of all processes executing on Linux except process 0.

64 3.4.2 Process Creation(3/3) Linux startup process
The init process is the last step in the boot procedure The init process is the last step in the boot procedure

65 3.4 Process Control 3.4.1 Modes of Execution 3.4.2 Process Creation
3.4.3 Process Switching

66 3.4.3 Process Switching(1/3) All processes begin execution in user mode, and they switch to kernel mode only when obtaining a service provided by the kernel. P137

67 3.4.3 Process Switching(2/3) Mode Switching: User Mode -> Kernel Mode 1. Interrupt Clock interrupt: process has executed for the maximum allowable time slice I/O interrupt Memory fault: Referenced virtual address is not in main memory, so it must be brought in. 2. Trap error or exception occurred, may cause process to be moved to Exit state 3. Supervisor call (System Call) such as file open A process switch may occur any time that the OS has gained control from the currently running process. The possible events that may give control to the OS include interrupt, trap and system call.

68 3.4.3 Process Switching(3/3) Steps involved in a full process switch
Save context of processor including program counter and other registers Update the process control block of the process and change the process's state that is currently in the Running state Move process control block to appropriate queue – ready; blocked; ready/suspend Select another process for execution Update the process control block of the process selected and change it state Update memory-management data structures Restore context of the selected process

69 Chap3 Process Description and Control
3.1 What is a Process 3.2 Process States 3.3 Process Description 3.4 Process Control 3.5 Execution of the Operating System

70 3.5 Execution of the OS(1/4) 1. Nonprocess Kernel(无进程的内核)
Execute kernel outside of any process Operating system code is executed as a separate entity that operates in privileged mode Common on many older OSs

71 3.5 Execution of the OS(2/4) 2. Execution Within User Processes(在用户进程中 执行) Operating system software within context of a user process Process executes in privileged mode when executing operating system code

72 3.5 Execution of the OS(3/4)

73 3.5 Execution of the OS(4/4) 3. Process-Based Operating System(基于进程的 OS) Implement operating system as a collection of system processes Useful in multi-processor or multi-computer environment

74 Homework Review Questions: 3.5 3.10 Problems: 3.1 3.3


Download ppt "Chapter 3 Process Description and Control"

Similar presentations


Ads by Google