Ch03 OS9e

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 56

Operating

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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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
© 2017 Pearson Education, Inc., Hoboken, NJ. 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
© 2017 Pearson Education, Inc., Hoboken, NJ. 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

© 2017 Pearson Education, Inc., Hoboken, NJ. 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

Memory I/O status Accounting


Context data
pointers information information
© 2017 Pearson Education, Inc., Hoboken, NJ. 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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process States
Trace Dispatcher
The behavior of an
individual process
by listing the
sequence of Small program
instructions that that switches the
execute for that processor from
process one process to
another

The behavior of the processor


can be characterized by
showing how the traces of the
various processes are
interleaved

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process
Execution

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Two-State Process Model

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 3.1 Reasons for Process Creation

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Creation
Process Parent
Child process
spawning process
• When the OS • Is the • Is the new
creates a original, process
process at the creating,
explicit process
request of
another
process

© 2017 Pearson Education, Inc., Hoboken, NJ. 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)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.2
Reasons for
Process
Termination

(Table is located on page 111


in the textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Five-State Process Model

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. 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 performance

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.3 Reasons for Process Suspension

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


File Tables
These tables provide
information about:
• Existence of files
• Location on secondary
memory

• may be maintained
InformationCurrent status
and used by a file management system
In•which
Other
case theattributes
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

© 2017 Pearson Education, Inc., Hoboken, NJ. 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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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:
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.4
Typical Elements of a Process Image

© 2017 Pearson Education, Inc., Hoboken, NJ. 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)

© 2017 Pearson Education, Inc., Hoboken, NJ. 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)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Processor State Information

• User-visible
• Contains condition
Consists registers codes plus other
of the
contents • Control and Progra status information
of status m status • EFLAGS register is
processo word an example of a
registers PSW used by any
r (PSW)
registers • Stack OS running on an
pointers x86 processor

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. 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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Modes of Execution
User Mode System Mode

 Less-privileged mode  More-privileged mode


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.7

Typical
Functions
of an
Operating
System
Kernel

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.8
Mechanisms for Interrupting the
Execution of a Process

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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 the
execute before being design of the OS
interrupted

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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

If the currently running process is to be moved to another


state (Ready, Blocked, etc.), then the OS must make Select another
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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Unix SVR4
 Uses the model 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

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.9 UNIX Process States

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table

3.10

UNIX

Process

Image

(Table is located on
page 140 in the
textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Table 3.11
UNIX
Process
Table
Entry

(Table is located on page 141 in the


textbook)

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Process Control
 Process creation • Allocates a slot in the process table for the new process
1
is by means of
the kernel • Assigns a unique process ID to the child process
system call, 2
fork() • Makes a copy of the process image of the parent, with the
3 exception of any shared memory
 When a process
issues a fork • Increments counters for any files owned by the parent, to reflect
4 that an additional process now also owns those files
request, the OS
performs the • Assigns the child process to the Ready to Run state
following 5
functions: • Returns the ID number of the child to the parent process, and a
6 0 value to the child process

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


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. Control returns to user mode at the point
of the fork call of the parent.
 Transfer control to the child process. The child process begins
executing at the same point in the code as the parent, namely at the
return from the fork call.
 Transfer control to another process. Both parent and child are left
in the Ready to Run state.

© 2017 Pearson Education, Inc., Hoboken, NJ. 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 system
 Creation and termination  Nonprocess kernel
 Five-state model
 Execution within user processes
 Suspended processes
 Process-based operating system

 UNIX SVR4 process management


 Process description
 Process states
 Operating system control structures
 Process description
 Process control structures
 Process control

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

You might also like