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
Concepts
A computer platform The OS was developed to
consists of a collection of provide a convenient,
hardware resources feature-rich, secure, and
consistent interface for
Computer applications applications to use
are developed to perform
some task We can think of the OS as
providing a uniform,
abstract representation of
It is inefficient for resources that can be
applications to be written requested and accessed by
directly for a given
hardware platform applications
OS Management of
Application Execution
Resources are made available to multiple
applications
Theprocessor is switched among multiple
applications so all will appear to be
progressing
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
characterized 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
occurred
Created and managed by the
operating system
Key tool that allows support for
multiple processes
Process
Execution
Traces of
Each process runs to completion
Processes
of
Figure 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 • is the new
creates a original, process
process at the creating,
explicit process
request of
another
process
Process Termination
There must be a means for a process to indicate its
completion
A batch job should include a HALT instruction or an
explicit 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,
quitting 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
Suspended Process
The process is not The process may or may
immediately available for not be waiting on an
execution event
The process was placed The process may not be
in a suspended state by an removed from this state
agent: either itself, a until the agent explicitly
parent process, or the OS, orders the removal
for the purpose of
preventing 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
some sort of virtual memory memory to processes
or simple swapping
protection attributes of blocks
mechanism 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 progress, the OS needs to
channels of the computer know:
system
the status of the I/O
At any given time, an I/O operation
device may be available or
assigned to a particular
process the location in main
memory 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
managed 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
management
Process Control Structures
To manage
• where the
and process is located
control 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 The collection of program, data,
programs and data of that process stack, and attributes is referred to
as the process image
The execution of a program
typically involves a stack that is Process image location will
used to keep track of procedure depend on the memory
calls and parameter passing management scheme being used
between procedures
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 process
otherwise there must be a 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 with
Many of the tables controlled by one another, the process identifier
the OS may use process identifiers informs the OS of the destination
to cross-reference process tables of a particular communication
When processes are allowed to
create other processes, identifiers
indicate the parent and
descendents of each process
Processor State Information
Consists of the Program status word
contents of (PSW)
processor registers • contains condition codes plus
• user-visible registers other status information
• control and status • EFLAGS register is an
registers example of a PSW used by
• stack pointers any OS running on an x86
processor
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
execute in this mode control 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 nature of the error
execute before being
interrupted
Mode Switching
If no interrupts are If an interrupt is
pending the processor: pending the processor:
proceeds to the fetch stage and fetches the
sets the program counter to the starting
next instruction of the current program in
address of an interrupt handler program
the current process
switches from user mode to kernel mode so
that the interrupt processing code may
include 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
execution
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