0% found this document useful (0 votes)
43 views46 pages

CH 03 - Process Description and Controls

The operating system manages computer resources and allows applications to run concurrently through processes. A process contains code, data, and process control information. The OS switches the processor rapidly between processes to give the appearance that all are running simultaneously. Processes can be in various states like running, ready, blocked, or terminated as they execute and interact with the OS and other processes.

Uploaded by

ramon luthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views46 pages

CH 03 - Process Description and Controls

The operating system manages computer resources and allows applications to run concurrently through processes. A process contains code, data, and process control information. The OS switches the processor rapidly between processes to give the appearance that all are running simultaneously. Processes can be in various states like running, ready, blocked, or terminated as they execute and interact with the OS and other processes.

Uploaded by

ramon luthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Operating

Systems:
Internals
and Design
Principles Process Description
and Control
 A computer platform  The OS was developed to
consists of a collection provide a convenient,
of 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,
 It is inefficient for abstract representation of
applications to be
written directly for a resources that can be
given hardware platform requested and accessed by
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
 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
 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
Identifier
State
Process Control Priority
Program counter
Block Memory pointers

Context data

Contains the process elements I/O status


information
It is possible to interrupt a running
Accounting
process and later resume execution as
information
if the interruption had not occurred

Created and managed by the


operating system

Key tool that allows support for


multiple processes

Figure 3.1 Simplified Process Control Block


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
Address Main Memory Program Counter
0
8000
100

Process
Dispatcher

5000

Execution 8000
Process A

Process B

12000

Process C

Figure 3.2 Snapshot of Example Execution (Figure 3.4)


at Instruction Cycle 13
5000 8000 12000
5001 8001 12001
5002 8002 12002
5003 8003 12003
5004 12004
5005 12005
5006 12006
5007 12007
5008 12008
5009 12009
5010 12010
5011 12011
(a) Trace of Process A (b) Trace of Process B (c) Trace of Process C

5000 = Starting address of program of Process A


8000 = Starting address of program of Process B
12000 = Starting address of program of Process C

Figure 3.3 Traces of Processes of Figure 3.2


1 5000 27 12004
2 5001 28 12005
3 5002 -------------------- Timeout
4 5003 29 100
5 5004 30 101
6 5005 31 102
-------------------- Timeout 32 103
7 100 33 104
8 101 34 105
9 102 35 5006
10 103 36 5007
11 104 37 5008
12 105 38 5009
13 8000 39 5010
14 8001 40 5011
15 8002 -------------------- Timeout
16 8003 41 100
----------------I/O Request 42 101
17 100 43 102
18 101 44 103
19 102 45 104
20 103 46 105
21 104 47 12006
22 105 48 12007
23 12000 49 12008
24 12001 50 12009
25 12002 51 12010
26 12003 52 12011
-------------------- Timeout

100 = Starting address of dispatcher program


Shaded areas indicate execution of dispatcher process;
first and third columns count instruction cycles;
second and fourth columns show address of instruction being executed

Figure 3.4 Combined Trace of Processes of Figure 3.2


Two-State Process Model

Dispatch

Enter Not Exit


Running Running

Pause

(a) State transition diagram


Pause

(a) State transition diagram

Queue
Enter Dispatch Exit
Processor

Pause

(b) Queuing diagram

Figure 3.5 Two-State Process Model


Process Creation
Process
spawning Parent process Child process

• when the • is the • is the new


OS creates a original, process
process at creating,
the 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)
Five-State Process Model
Dispatch
Admit Release
New Ready Running Exit
Timeout

Event
Occurs Event
Wait

Blocked

Figure 3.6 Five-State Process Model


BATAS
KELOMPOK
Process A

Process B

Process C

Dispatcher

0 5 10 15 20 25 30 35 40 45 50

= Running = Ready = Blocked

Figure 3.7 Process States for Trace of Figure 3.4


Ready Queue Release
Admit Dispatch
Processor

Timeout

Blocked Queue
Event Event Wait
Occurs
(a) Single blocked queue

Ready Queue Release


Admit Dispatch
Processor

Timeout

Event 1 Queue
Event 1 Event 1 Wait
Occurs

Event 2 Queue
Event 2 Event 2 Wait
Occurs

Event n Queue
Event n Event n Wait
Occurs

(b) Multiple blocked queues

Figure 3.8 Queuing Model for Figure 3.6


 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
(a) With One Suspend State

New

Ad
t
Dispatch
mi
Admit Release

mi
Ad
New Ready Suspend Running Exit

t
Timeout
Activate Dispatch
Ready/ Release

it
Ready Running Exit

Occurs Occurs

a
e

Event Event
at

tW
Suspend
iv

Suspend Timeout
ct

t W ven
A

t
ai
Occurs
Event

Suspend

en
Suspend Blocked

Ev
Activate
Blocked/
Suspend (a)Blocked
With One Suspend State
Suspend

(b) With Two Suspend States


New

Figure 3.9 Process State Transition Diagram with Suspend States


Ad
t
mi

mi
Ad

Suspe
t

nd
(a) With One Suspend State

New

Ad
t
mi

mi
Ad

Suspe

t
nd

Activate Dispatch
Ready/ Release
Suspend Ready Running Exit
Suspend Timeout

t
ai
Occurs

Occurs
Event

Event

tW
en
Ev
Activate
Blocked/
Suspend
Blocked
Suspend

(b) With Two Suspend States

Figure 3.9 Process State Transition Diagram with Suspend States


 The process is not  The process may or may
immediately available not be waiting on an
for execution event

 The process was placed  The process may not be


in a suspended state by removed from this state
an agent: either itself, a until the agent explicitly
parent process, or the
orders the removal
OS, for the purpose of
preventing its execution
P1 P2 Pn
Virtual
Memory

Computer
Resources
Main
Processor I/O I/O I/O
Memory

Figure 3.10 Processes and Resources (resource allocation at one snapshot in time)
Process
Image
Memory Tables
Process
Memory 1

Devices I/O Tables

Files

Processes File Tables

Primary Process Table

Process 1

Process 2
Process
Process 3 Image
Process
n

Process n

Figure 3.11 General Structure of Operating System Control Tables


 Used to keep track of both
main (real) and secondary
(virtual) memory

 Processes are maintained


on secondary memory
using some sort of virtual
memory or simple
swapping mechanism
 Used by the OS to manage
the I/O devices and
channels of the computer
system

 At any given time, an I/O


device may be available or
assigned to a particular
process
These tables provide
information about:
• existence of files
• location on secondary
memory

• current status
Information may be maintained and used by a file management system
 in•which
other attributes
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
 Must be maintained to manage processes
 Theremust 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
To manage • where the
and process is
located
control a • the attributes of
process the the process that
OS must are necessary for
know: its management
Process Location Process Attributes
 A process must include a  Each process has associated with
program or set of programs to be it a number of attributes that are
executed 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 stack, and attributes is referred to
process as the process image
 The execution of a program  Process image location will
typically involves a stack that is depend on the memory
used to keep track of procedure management scheme being used
calls and parameter passing
between procedures
BATAS KELOMPOK
Table 3.4
Typical Elements of a Process Image

User Data
The modifiable part of the user space. May include program data, a user stack area, and
programs that may be modified.

User Program
The program to be executed.

Stack
Each process has one or more last-in-first-out (LIFO) stacks associated with it. A stack is
used to store parameters and calling addresses for procedure and system calls.

Process Control Block


Data needed by the OS to control the process (see Table 3.5).
 Memory tables may be
 Each process is assigned a organized to provide a map of
unique numeric identifier main memory with an indication
of which process is assigned to
 otherwise there must be a each region
mapping that allows the OS  similar references will appear in
to locate the appropriate I/O and file tables
tables based on the process
identifier  When processes communicate
with one another, the process
identifier informs the OS of the
 Many of the tables controlled by destination of a particular
the OS may use process communication
identifiers to cross-reference
process tables  When processes are allowed to
create other processes,
identifiers indicate the parent
and descendents of each
process
• user-visible
• contains condition
Consists registers codes plus other
of the • control and Program status information
contents status • EFLAGS register
of status
word is an example of a
processor registers (PSW) PSW used by any
registers
• stack OS running on an
x86 processor
pointers
 The additional information
needed by the OS to control
and coordinate the various
active processes
Process Process Process
Identification Identification Identification
Process
Processor State Processor State Processor State Control
Information Information Information Block
Process Control Process Control Process Control
Information Information Information

User Stack User Stack User Stack

Private User Private User Private User


Address Space Address Space Address Space
(Programs, Data) (Programs, Data) (Programs, Data)

Shared Address Shared Address Shared Address


Space Space Space

Process 1 Process 2 Process n

Figure 3.13 User Processes in Virtual Memory


Process
Control Block
Running

Ready

Blocked

Figure 3.14 Process List Structures


 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
User Mode System Mode

 less-privileged mode  more-privileged mode


 user programs  also referred to as
typically execute in control mode or
this mode kernel mode
 kernel of the
operating system
 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
Table 3.8
Mechanisms for Interrupting the
Execution of a Process

Mechanism Cause Use

Interrupt External to the execution of the Reaction to an asynchronous


current instruction external event

Trap Associated with the execution of Handling of an error or an


the current instruction exception condition

Supervisor call Explicit request Call to an operating system


function
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
 clock interrupt  OS determines if the
 I/O interrupt
condition is fatal
 memory fault  moved to the Exit state

 Time slice and a process switch


occurs
 the maximum amount of
time that a process can  action will depend on the
execute before being nature of the error
interrupted
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
 The steps in update the process
move the process
a 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 select another
make substantial changes in its environment process for
execution

restore the context


of the processor to
that which existed
at the time the update memory update the process
selected process was management data control block of
last switched out structures the process
selected
Execution
P1 P2 Pn

Kernel

of the (a) Separate kernel

Operating P1 P2 Pn

System
OS OS OS
Func- Func- Func-
tions tions tions

Process Switching Functions

(b) OS functions execute within user processes

P1 P2 Pn OS1 OSk

Process Switching Functions

(c) OS functions execute as separate processes

Figure 3.15 Relationship Between Operating


System and User Processes
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

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

You might also like