You are on page 1of 54

Operating

Systems:
Internals
and Design Chapter 3
Principles Process Description
and Control
Seventh Edition
By William Stallings
Operating Systems:
Internals and Design Principles

The concept of process is fundamental to the structure of


modern computer operating systems. Its evolution in
analyzing problems of synchronization, deadlock, and
scheduling in operating systems has been a major
intellectual contribution of computer science.

WHAT CAN BE AUTOMATED?:


THE COMPUTER SCIENCE AND
ENGINEERING RESEARCH STUDY,
MIT Press, 1980
Summary of Earlier Con-
cepts
 A computer platform  The OS was developed to
consists of a collection of provide a convenient, fea-
hardware resources ture-rich, secure, and con-
sistent interface for applica-
 Computer applications tions to use
are developed to perform
some task  We can think of the OS as
providing a uniform, ab-
stract representation of re-
 It is inefficient for appli- sources that can be re-
cations to be written di- quested and accessed by
rectly for a given hard-
ware platform applications
OS Management of Applica-
tion Execution
 Resources are made available to multiple
applications
 Theprocessor is switched among multiple
applications so all will appear to be progress-
ing
 The processor and I/O devices can be used
efficiently
Process Elements
 Two essential elements of a process are:

Program code
 which may be shared with other processes that are executing the
same program

A set of data associated with that code



When the processor begins to execute the program code, we refer to
this executing entity as a process
Process Elements
 While the program is executing, this process can be uniquely character-
ized by a number of elements, including:

identifier

program
state priority
counter

memory I/O status accounting


context data
pointers information information
Process Control
Block
Contains the process elements
It is possible to interrupt a running
process and later resume execution
as if the interruption had not oc-
curred

Created and managed by the oper-


ating system

Key tool that allows support for


multiple processes
Process States
Trace Dispatcher

the behavior of an
individual process small program
by listing the se- that switches the
quence of instruc- processor from
tions that execute one process to
for that process another

the behavior of the processor


can be characterized by show-
ing how the traces of the vari-
ous processes are interleaved
Process Ex-
ecution
Traces of
 Each process runs to completion
Processes
of Fig-
ure 3.2

Figure 3.3
Combined
Trace of
Processes of
Figure
3.2

Figure 3.4
Two-State Process Model
 A process may be in one of two states:
 running
 not-running
Queuing Diagram
Table 3.1 Reasons for Process Creation
Process Creation
Process Parent
spawning Child process
process
• when the OS • is the origi- • is the new
creates a nal, creating, process
process at the process
explicit re-
quest of an-
other process
Process Termination
 There must be a means for a process to indicate its comple-
tion
 A batch job should include a HALT instruction or an expli-
cit OS service call for termination
 For an interactive application, the action of the user will
indicate when the process is completed (e.g. log off, quit-
ting an application)
Table 3.2
Reasons
for Process
Termination
Five-State Process Model
Process States for Trace of Figure 3.4
Using Two Queues
Multiple
Blocked
Queues
Suspended Processes
 Swapping
 involves moving part of all of a process from main memory to disk
 when none of the processes in main memory is in the Ready state, the OS
swaps one of the blocked processes out on to disk into a suspend queue
One Suspend State
Two Suspend States
Characteristics of a Sus-
pended Process
 The process is not imme-  The process may or may
diately available for exe- not be waiting on an
cution event

 The process was placed  The process may not be


in a suspended state by an removed from this state
agent: either itself, a par- until the agent explicitly
ent process, or the OS, orders the removal
for the purpose of pre-
venting its execution
Reasons for Process Suspension

Table 3.3 Reasons for Process Suspension


Processes and Resources
OS
Control
Tables
Memory Tables
 Used to keep track of both
main (real) and secondary Must include:
(virtual) memory
allocation of main memory to
 Processes are maintained on processes
secondary memory using
allocation of secondary mem-
some sort of virtual memory ory to processes
or simple swapping mech-
protection attributes of blocks
anism of main or virtual memory

information needed to manage


virtual memory
I/O Tables
 Used by the OS to manage If an I/O operation is in
the I/O devices and chan- progress, the OS needs to
nels of the computer system know:
 At any given time, an I/O
the status of the I/O opera-
device may be available or tion
assigned to a particular
process
the location in main mem-
ory being used as the
source or destination of the
I/O transfer
These tables provide
information about:
File Tables • existence of files
• location on secondary
memory
• current status
• other attributes
 Information may be maintained and used by a file management system
 in which case the OS has little or no knowledge of files

 In other operating systems, much of the detail of file management is man-


aged by the OS itself
Process Tables
 Must be maintained to manage processes
 There must be some reference to memory, I/O,
and files, directly or indirectly
 Thetables themselves must be accessible by the
OS and therefore are subject to memory man-
agement
Process Control Structures

To manage
• where the
and con- process is located
trol a • the attributes of
process the process that
the OS are necessary for
its management
must
know:
Process Control Structures
Process Location Process Attributes
 A process must include a program  Each process has associated with
or set of programs to be executed it a number of attributes that are
used by the OS for process control
 A process will consist of at least
sufficient memory to hold the pro-  The collection of program, data,
grams and data of that process stack, and attributes is referred to
as the process image
 The execution of a program typi-
cally involves a stack that is used  Process image location will de-
to keep track of procedure calls and pend on the memory management
parameter passing between proce- scheme being used
dures
Typical Elements of a Process Image
Process Attributes
Process Identification
 Memory tables may be organized
 Each process is assigned a unique
to provide a map of main memory
numeric identifier
with an indication of which
 otherwise there must be a process is assigned to each region
mapping that allows the OS to  similar references will appear in
locate the appropriate tables I/O and file tables
based on the process identifier
 When processes communicate
 Many of the tables controlled by with one another, the process iden-
the OS may use process identifiers tifier informs the OS of the desti-
to cross-reference process tables nation of a particular communica-
tion
 When processes are allowed to
create other processes, identifiers
indicate the parent and descen-
dents of each process
Processor State Information

Consists of the Program status word


contents of pro- (PSW)
cessor registers • contains condition codes plus
• user-visible registers other status information
• control and status regis- • EFLAGS register is an ex-
ters ample of a PSW used by any
• stack pointers OS running on an x86 pro-
cessor
X86 EFLAGS Register
Table 3.6

Pentium

EFLAGS

Register

Bits
Process Control
Information
 The additional information needed by the OS to
control and coordinate the various active processes
Typical

Elements

of a Process

Control Block
Structure of Process
Images in Virtual Memory
Process List Structures
Role of the
Process Control Block
 The most important data structure in an OS
 contains all of the information about a process that is needed by the OS
 blocks are read and/or modified by virtually every module in the OS
 defines the state of the OS

 Difficulty is not access, but protection


 a bug in a single routine could damage process control blocks, which could
destroy the system’s ability to manage the affected processes
 a design change in the structure or semantics of the process control block
could affect a number of modules in the OS
Modes of Execution
User Mode System Mode

 less-privileged mode  more-privileged mode


 user programs typically  also referred to as con-
execute in this mode trol mode or kernel
mode
 kernel of the operating
system
Table 3.7

Typical

Functions

of an

Operating

System

Kernel
Process Creation
 Once the OS decides to create a new process it:
assigns a unique process identifier to the
new process

allocates space for the process

initializes the process control block

sets the appropriate linkages

creates or expands other data structures


Process Switching
A process switch may occur any time that the OS has gained control from the
currently running process. Possible events giving OS control are:
System Interrupts
Interrupt Trap
 Due to some sort of event that  An error or exception condition
is external to and independent generated within the currently
of the currently running process running process
 clock interrupt  OS determines if the condition
 I/O interrupt is fatal
 memory fault  moved to the Exit state and
 Time slice a process switch occurs
 the maximum amount of  action will depend on the
time that a process can exe- nature of the error
cute before being interrupted
Mode Switching

If no interrupts are If an interrupt is pend-


pending the processor: ing the processor:

proceeds to the fetch stage and fetches the


sets the program counter to the starting ad-
next instruction of the current program in
dress of an interrupt handler program
the current process

switches from user mode to kernel mode so


that the interrupt processing code may in-
clude privileged instructions
Change of Process State
 The steps in a
update the process move the process
full process save the context of control block of the control block of
the processor
switch are: process currently in this process to the
the Running state appropriate queue

If the currently running process is to be moved to


another state (Ready, Blocked, etc.), then the OS select another
must make substantial changes in its environment process for execu-
tion

restore the context


of the processor to
that which existed at
the time the selected update memory update the process
process was last management data control block of the
switched out structures process selected
Execution
of the
Operating System
Execution Within
User Processes

You might also like