Transcript Processes

Process Description and Control
Chapter 3
1
Requirements of an
Operating System



Interleave the execution of multiple
processes to maximize processor
utilization while providing reasonable
response time
Allocate resources to processes
Support interprocess communication
and user creation of processes
2
What is a Process?




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, and an associated set of
system resources
3
Process Elements








A process is an entity that consists of a number
of elements. Two essential elements are program
code(程序代码) and a set of data(与代码相关的数
据集). When the program is executing, it need
include the following elements:
Identifier(标识符)
State(进程状态)
Priority(优先级)
Program counter(程序计数器)
Memory pointers(内存指针)
Context data(上下文数据)
I/O status information(I/O状态信息)
Accounting information(统计信息)
4
Process Control Block(PCB,
进程控制块)



Contains the process elements
Created and manage by the
operating system
Allows OS to support for multiple
processes
5
Process Control Block
So, a process consists
of program code and
associated data plus
a PCB
6
Trace of Process


Sequence of instruction that execute
for a process
Dispatcher switches the processor
from one process to another
7
Example Execution
8
Trace of Processes
9
10
Two-State Process Model

Process may be in one of two states
 Running
 Not-running
11
Not-Running Process in a Queue
When the operating system creates a new
process, it enters the process into the system
in the Not-running state.
12
Process Creation
The operating system builds
the data structures that are
used to manage the process and
allocates address space in main
memory to the process.
13
Process Creation
14
Process Termination
15
16
Processes


Not-running
 Ready to execute
 Blocked
 waiting for I/O
Dispatcher cannot just select the process
that has been in the queue the longest
because it may be blocked
17
A Five-State Model





Running(运行)
Ready(就绪)
Blocked(阻塞)
New(新建): PCB has been
created, but not loaded into main
memory
Exit(退出)
18
Five-State Process Model
19
Process States
20
Using Two Queues
21
Multiple Blocked Queues
22
Suspended(挂起) Processes



Processor is faster than I/O so all
processes could be waiting for I/O
Swap these processes to disk to free up
more memory
Blocked state becomes suspend state
when swapped to disk
23
One Suspend State
24
Two Suspend States
Blocked/Suspend(阻塞/挂起)
Ready/Suspend(就绪/挂起)
25
Reasons for Process Suspension
26
Processes and Resources
What information does the OS
need to control processes and
manage resources for them?
27
Operating System Control
Structures


Information about the current
status of each process and resource
Tables are constructed for each
entity the operating system manages

Four different types of tables:
memory, I/O, file, process
28
29
Memory Tables(存储表)




keep track of both main and secondary
memory.
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
30
I/O Tables(I/O表)



Manage the I/O devices and channels of
the computer system.
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
31
File Tables(文件表)





Existence of files
Location on secondary memory
Current Status
Attributes
Sometimes this information is
maintained by a file management system
32
Process Table(进程表)


Where process is located?
What its attributes are managed?

Process include:
 Program
 Data
 Stack
 Attributes
in the process control block
33
Process Image(进程映象)
34
Process Control Block(PCB,
进程控制块)



Contains the process elements
Created and manage by the
operating system
Allows support for multiple
processes
35
Process Control Block
Three general categories:
 Process identification(进程标识)
 Processor State Information(进程状
态信息)
 Process Control Information(进程控
制信息)
36
Process identification

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 (parent
process)
 User identifier
37
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.
Control and Status Registers
 These are a variety of processor
registers that are employed to control
the operation of the processor.
Stack Pointers
38
Process Control Information



Scheduling and State Information
 Process state(进程状态)
 Priority(优先级)
 Scheduling-related information(相关调
度信息)
 Event(进程等待的事件)
Data Structuring
Interprocess Communication
39
Process Control Information

Process Privileges(进程特权)


Memory Management


Allow to access memory and to execute some
instructions
This section may include pointers to segment
and/or page tables that describe the virtual
memory assigned to this process.
Resource Ownership and Utilization
40
Process Control Block
41
Process Control
Modes of Execution
 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
42
Process Creation





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
43
When to Switch a Process



Clock interrupt
 process has executed for the
maximum allowable time slice
I/O interrupt
Memory fault
 memory address is in virtual memory
so it must be brought into main
memory
44
When to Switch a Process


Trap
 error or exception occurred
 may cause process to be moved to
Exit state
Supervisor call
 such as file open
45
Steps of Process Switch




Save context of processor including
program counter and other registers
Update the process control block of the
process that is currently in the Running
state
Move process control block to
appropriate queue – ready; blocked;
ready/suspend
Select another process for execution
46
Steps of Process Switch



Update the process control block of the
process selected: Running
Update memory-management data
structures
Restore context of the selected process:
load in the previous values of the PC
and other register
47
Execution of the Operating System
Is the operating system a process?
 Non-process Kernel
 Execute kernel outside of any process
 Operating system code is executed as a
separate entity that operates in privileged
mode
 Execution Within User Processes
 Operating system software within context of a
user process
 Process executes in privileged mode when
executing operating system code
48
Execution of the Operating System

Process-Based Operating System
 Implement operating system as a
collection of system processes
 Useful in multi-processor or multicomputer environment
49
50