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

CH03 - Process_Description_and_Control

This document discusses the fundamentals of operating systems, focusing on process management, including process creation, execution, and termination. It explains the structure and role of the Process Control Block (PCB) and the importance of managing resources efficiently among multiple applications. Additionally, it covers various states of processes and the mechanisms for handling interrupts and mode switching in operating systems.

Uploaded by

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

CH03 - Process_Description_and_Control

This document discusses the fundamentals of operating systems, focusing on process management, including process creation, execution, and termination. It explains the structure and role of the Process Control Block (PCB) and the importance of managing resources efficiently among multiple applications. Additionally, it covers various states of processes and the mechanisms for handling interrupts and mode switching in operating systems.

Uploaded by

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

Operatin

g Chapter 3
Systems:
Internals Process
and Description and
Design
Principles
Control
Eighth Edition
Global Edition
By William Stallings
Summary of Earlier
Concepts
 A computer platform  The OS was developed
consists of a collection to provide a
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 platform representation of
resources that can be
requested and
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
 Theprocessor 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
accountin
context I/O status
memory g
data informati
pointers informati
(data in registers) on
on
Process Control
Block (Simplified)
Contains the process
elements
Created and managed by
the operating system
It is possible to interrupt
a running process and
later resume execution as
if the interruption had not
occurred
Key tool that allows
support for multiple
Process & Processor
behavior
the behavior of an Dispatch
Trace
individual process er
by listing the
sequence of
instructions that small program
execute for that that switches the
process processor from
one process to
another
the behavior of the
processor can be
characterized by
showing how the
traces of the various
processes are
interleaved
Process
Execution
The same assume that the OS
sequence of only allows a
instructions is process to continue
executed by the execution for a
dispatcher in each maximum of six
instance because instruction cycles,
the same after which it is
functionality of the interrupted
dispatcher is
being executed
Two-State Process
Model
Table 3.1 Reasons for
Process Creation
Process Creation
Process Parent Child
spawning process process
• when the • is the • is the
OS original, new
creates a creating, process
process process
at the
explicit
request
of
another
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)
Table3.
2Reasons
for
Process
Terminati
on

(Table is located on
page 145 in the
textbook)
Five-State Process
Model

Control block
is created for
the new
process 2-sate is not enough when:
Some processes in the Not
Running state are ready to
execute, while others are
blocked, waiting for an I/O
operation to complete
Fig 3.8:
Queuing
Model for Fig
3.6
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
 Makes room for a new process that is not blocked
Difficulty:
All of the processes that have
been suspended were in the
Blocked state at the time of
suspension. It clearly would
not do any good to bring a
blocked process back into
main memory, because it is
still not ready for execution.
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
placed in a  The process may
suspended state by not be removed
an agent: either from this state until
itself, a parent the agent explicitly
process, or the OS, orders the removal
for the purpose of
preventing its
execution
Table 3.3 Reasons for Process
Suspension
Blocked waiting for
has control of two an I/O device
allocated to P1 suspended
I/O devices
If the OS is to manage processes and resources, it must have information
about the current status of each process and resource

Explained
in p.32
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
such as which processes may access
certain shared memory regions
I/O Tables
 Used by the OS to
manage the I/O
devices and channels If an I/O operation is
of the computer in progress, the OS
system needs 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
to a particular process source or destination of
the I/O transfer
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
Process Tables
 Mustbe 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
process of the process
the OS that are
necessary for
must its
know: management
process ID, state,
priority, etc.
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
procedure calls and will depend on the memory
parameter passing between management scheme
procedures being used
Table 3.4
Typical Elements of a Process
Image
Table 3.5

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

(Table is located
on page 159 in the
textbook)
Table 3.5
Typical
Elements of
a Process
Control Block

(page 2 of 2)

(Table is located
on page 159 in the
textbook)
1. Process
Identification
 Memory tables may be
 Each process is assigned a organized to provide a map of
unique numeric identifier main memory with an indication
 otherwise there must be of which process is assigned to
each region
a mapping that allows  similar references will appear in
the OS to locate the 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
communication
use process identifiers to
cross-reference process  When processes are allowed to
tables create other processes,
identifiers indicate the parent
 For example: memory
and descendents of each
tables process
2. Processor State
Information
• user- • contains
visible condition codes
Consists registers plus other
Progra status
of the • control information
contents m
of and status • EFLAGS register
processo
r
status word is an example
registers (PSW) of a PSW used
registers
by any OS
• stack A register or
running on an
a set of
pointers registers x86 processor
in Chapter 1
3. Process Control
Information
 Theadditional information
needed by the OS to control
and coordinate the various
active processes
Process
image 1
the process control block may contain
structuring information, including
pointers that allow the linking of
process control blocks
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
 more-privileged
 less-privileged
mode
mode
 also referred to as
 user programs control mode or
typically execute kernel mode
in this mode  refers to 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: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
Table 3.8
Mechanisms for Interrupting
the Execution of a Process
System Interrupts
Interrupt Trap
 Due to some sort of event  An error or exception
that is external to and condition generated within
independent of the currently the currently running process
running process  OS determines if the
 clock interrupt
condition is fatal
 I/O interrupt  moved to the Exit state
 memory fault and a process switch
 Time slice (for clock interrupt) occurs
 the maximum amount of  action will depend on the
time that a process can nature of the error
execute before being (process switch or
interrupted resume)
Mode Switching in
Interrupt Stage
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
Change of Process
State
update the move the
 The steps in save the process process
a full context of the control block control block
process processor of the process of this process
switch are: currently in to the
the Running appropriate
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
environment execution
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 selected
switched out
execute

Execution the kernel of


the OS
outside of
of the any process

Operating
System
Execution
Within
User Processes

used to manage
calls/returns while the
process is in kernel mode
Unix SVR4
 Uses the model (Figure 3.15b) where most of the OS
executes within the environment of a user process
 System processes run in kernel mode
 executes operating system code to perform administrative
and housekeeping functions

 User Processes
 operate in user mode to execute user programs and utilities
 operate in kernel mode to execute instructions that belong to
the kernel
 enter kernel mode by issuing a system call, when an exception
is generated, or when an interrupt occurs
Table 3.9 UNIX Process
States
Table

3.10

UNIX

Proces

Image

(Table is located
on page 174 in
the textbook)
Table
3.11
UNIX
Process
Table
Entry

(Table is located on page 175


in the textbook)
Table 3.12
UNIX U
Area

(Table is located on page 176 in


the textbook)
Process
Creation
 Process • Allocate a slot in the process table for the new process
1
creation is
by means of • Assign a unique process ID to the child process
the kernel 2
system call, • Make a copy of the process image of the parent, with
fork( ) 3 the exception of any shared memory
• Increments counters for any files owned by the parent,
 This causes to reflect that an additional process now also owns
4 those files
the OS, in
Kernel Mode, • Assigns the child process to the Ready to Run state
to: 5

• Returns the ID number of the child to the parent


6 process, and a 0 value to the child process
After Creation
 After creating the process the Kernel can do one
of the following, as part of the dispatcher
routine:
 stay in the parent process
 transfer control to the child process
 transfer control to another process
Summary
 What is a process?  Process control
 Background  Modes of execution
 Processes and process control  Process creation
blocks  Process switching

 Process states  Execution of the operating system


 Two-state process model  Nonprocess kernel
 Creation and termination  Execution within user processes
 Five-state model
 Process-based operating system
 Suspended processes  UNIX SVR4 process management
 Process states
 Process description
 Process description
 Operating system control
structures
 Process control
 Process control structures

You might also like