0% found this document useful (0 votes)
14 views

Ch03-OS9e

Uploaded by

hussienayman366
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Ch03-OS9e

Uploaded by

hussienayman366
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Chapter 3

Process
Description and
Control
Ninth Edition, Global Edition
By William Stallings

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Summary of Earlier
Concepts
 A computer platform  The OS was developed
consists of a to provide a
collection of hardware
resources convenient, feature-
rich, secure, and
 Computer applications consistent interface
are developed to for applications to use
perform some task
 We can think of the
 It is inefficient for OS as providing a
applications to be uniform, abstract
written directly for a
given hardware representation of
platform resources that can be
requested and
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
OS Management of
Application Execution
 Resources are made available to
multiple applications
 The processor is switched among
multiple applications so all will
appear to be progressing
 The processor and I/O devices can
be used efficiently
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
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

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process Elements
 While the program is executing, this process can be
uniquely characterized by a number of elements,
including:

Identifier

Program
State Priority
counter
Accountin
I/O status
Memory Context g
informatio
pointers data informatio
n
n
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
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

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process States
Dispatch
Trace
The behavior of er
an individual
process by Small
listing the program that
sequence of switches the
instructions that processor
execute for that from one
process process to
another
The behavior of the
processor can be
characterized by
showing how the traces
of the various processes
are interleaved

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process
Execution

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Two-State Process
Model

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Table 3.1 Reasons for
Process Creation

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process Creation
Process Parent Child
spawning process process
• When the • Is the • Is the new
OS creates original, process
a process creating,
at the process
explicit
request of
another
process
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
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)

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Table
3.2
Reasons
for
Process
Terminati
on

(Table is located on
page 111
in the textbook)
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Five-State Process
Model

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
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
 This is a queue of existing processes that have been
temporarily kicked out of main memory, or suspended
 The OS then brings in another process from the suspend
queue or it honors a new-process request
 Execution then continues with the newly arrived process

 Swapping, however, is an I/O operation and therefore there is the


potential for making the problem worse, not better. Because disk
I/O is generally the fastest I/O on a system, swapping will usually
enhance
Copyright © 2018 performance
Pearson Education, Ltd. All Rights Reserved.
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Characteristics of a
Suspended Process
 The process is not  The process may or
immediately may not be waiting
available for on an event
execution
 The process was  The process may
placed in a not be removed
suspended state by from this state until
an agent: either the agent explicitly
itself, a parent orders the removal
process, or the OS,
for the purpose of
Copyright preventing its
© 2018 Pearson Education, Ltd. All Rights Reserved.
Table 3.3 Reasons for Process
Suspension

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Memory Tables
 Used to keep track of
both main (real) and
Must
secondary (virtual)
memory
include:
Allocation of main
memory to processes
 Processes are
maintained on Allocation of secondary
secondary memory memory to processes
Protection attributes of
using some sort of
blocks of main or virtual
virtual memory or memory
simple swapping Information needed to
mechanism manage virtual memory

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


I/O Tables
 Used by the OS to
manage the I/O
devices and channels If an I/O operation is in
of the computer progress, the OS needs
system to know:
• The status of the I/O
 At any given time, an operation
I/O device may be • The location in main
available or assigned memory being used as the
source or destination of the
to a particular process I/O transfer

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


File Tables
These tables provide
information about:
• 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

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process Tables
 Must be maintained to manage
processes
 There must be some reference to
memory, I/O, and files, directly or
indirectly
 The tables themselves must be
accessible by the OS and therefore are
subject to memory management
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Process Control
Structures
To
manage • Where the
and process is
control a located
• The attributes
process of the process
the OS that are
must necessary for
its
know: management
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Process Control
Structures
Process Location Process Attributes
 A process must include a  Each process has
program or set of programs associated with it a number
to be executed of attributes that are used
 A process will consist of at by the OS for process
least sufficient memory to control
hold the programs and data  The collection of program,
of that process data, stack, and attributes
 The execution of a program is referred to as the
typically involves a stack that process image
is used to keep track of  Process image location will
procedure calls and depend on the memory
parameter passing between management scheme
procedures being used
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Table 3.4
Typical Elements of a Process
Image

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Table 3.5

Typical
Elements
of a
Process
Control
Block
(page 1 of 2)

(Table is located
on page 125 in the
textbook)

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Table 3.5
Typical
Elements of
a Process
Control Block

(page 2 of 2)

(Table is located
on page 125 in the
textbook)
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Process
Identification
 Memory tables may be
 Each process is assigned a organized to provide a map of
unique numeric identifier main memory with an
 Otherwise there must be indication of which process is
a mapping that allows assigned to each region
the OS to locate the  Similar references will appear
in I/O and file tables
appropriate tables based
on the process identifier  When processes communicate
with one another, the process
 Many of the tables identifier informs the OS of the
controlled by the OS may destination of a particular
use process identifiers to communication
cross-reference process  When processes are allowed
tables
to create other processes,
identifiers indicate the parent
and descendents of each
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved. process
Processor State
Information
• User- • Contains
visible condition codes
Consist
s of the
registers plus other
• Control Progra status
content information
s of m
process
and status • EFLAGS register
or status word is an example
register registers of a PSW used
(PSW) by any OS
s • Stack running on an
pointers x86 processor

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Table 3.6

x86

EFLAGS

Register

Bits

(Table is located on page 127 in the


textbook)
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Process Control
Information
 The additional information
needed by the OS to control
and coordinate the various
active processes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
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

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Modes of Execution
User Mode System Mode

 Less-privileged  More-privileged
mode mode
 User programs  Also referred to as
typically execute control mode or
in this mode kernel mode
 Kernel of the
operating system

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Table 3.7

Typical
Functions
of an
Operating
System
Kernel

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process Creation
 Once the OS decides to create a new
process it:a unique process
Assigns
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
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Table 3.8
Mechanisms for Interrupting
the Execution of a Process

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


System Interrupts
Interrupt Trap
 Due to some sort of  An error or exception
event that is external to condition generated
and independent of the within the currently
currently running process running process
 Clock interrupt  OS determines if the
 I/O interrupt condition is fatal
 Memory fault  Moved to the Exit
 Time slice state and a process
 The maximum amount switch occurs
of time that a process  Action will depend on
can execute before the nature of the error
being interrupted the design of the OS
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Mode Switching
If no interrupts are If an interrupt is
pending the pending the
processor: processor:
Proceeds to the fetch stage and
Sets the program counter to the
fetches the next instruction of
starting address of an interrupt
the current program in the
handler program
current process

Switches from user mode to


kernel mode so that the
interrupt processing code may
include privileged instructions

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Change of Process
State
 The steps in Update the Move the
Save the process control process control
a full context of the block of the block of this
process processor process process to the
switch are: currently in the appropriate
Running state queue

If the currently running process is to be moved


to another state (Ready, Blocked, etc.), then Select another
the OS must make substantial changes in its process for
execution
environment
Restore the
context of the
processor to that
which existed at Update the
the time the Update memory process control
selected process management block of the
was last data structures process
switched out selected
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Execution
of the
Operating
System

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Execution
Within
User
Processes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Summary
 What is a process?  Process control
 Background  Modes of execution
 Processes and process control
blocks
 Process creation
 Process switching
 Process states
 Two-state process model  Execution of the operating
 Creation and termination system
 Five-state model  Nonprocess kernel
 Suspended processes
 Execution within user
 Process description processes
 Operating system control  Process-based
structures
operating system
 Process control structures

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Questions
1) A process is in the _________ state when it is in secondary memory
and awaiting an event.

2) Two essential elements of a process are __________ and a set of


data associated with that code.
3)The _________ tables provide information about the existence of files,
their location on secondary
memory, their current status, and other attributes.

4) A significant point about the __________ is that it contains sufficient


information so that it is possible
to interrupt a running process and later resume execution as if the
interruption had not occurred.

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.
Questions
5) When the OS creates a process at the explicit request of another process, the action is
referred to as __________ .

6) The process is said to be operating in a _________ fashion if each process in the queue is
given
a certain amount of time, in turn, to execute and then returned to the queue, unless
blocked.

7) A process in the _________ state is in main memory and available for execution.

8) _________ tables are used to keep track of both main (real) and secondary (virtual)
memory.

9) The process control block information can be grouped into three general categories:
process
identification, __________ and process control information.

10) A __________ is the maximum amount of time that a process can execute before being
interrupted.

Copyright © 2018 Pearson Education, Ltd. All Rights


11) The principal function of the OS is to create, manage, and ________ processes
Reserved.
Questions
13) The portion of the operating system that selects the next process
to run is called the _________ .

14) The collection of program, data, stack, and attributes is referred


to as the _________

15) A process is in the _________ state when it is in main memory


and awaiting an event.

16) We can characterize the behavior of an individual process by


listing the sequence of instructions, referred to as a __________, that
executes for that process.

17)An error or exception condition generated within the currently running process
is __________.

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.

You might also like