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

Lect 3

The document discusses processes and process management in an operating system. It defines what a process is, describes the elements that make up a process like program code and process control block. It also explains process states like running, ready, blocked/waiting, and concepts like context switching, dispatcher, and the need for swapping processes between main memory and disk.

Uploaded by

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

Lect 3

The document discusses processes and process management in an operating system. It defines what a process is, describes the elements that make up a process like program code and process control block. It also explains process states like running, ready, blocked/waiting, and concepts like context switching, dispatcher, and the need for swapping processes between main memory and disk.

Uploaded by

라치
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

1

Process
Description CHAPTER 3

and Control
2
Process

 A program in execution

 A unit of activity characterized by the execution of


a sequence of instructions, a current state, and an
associated set of system resources
3
Process Elements

 A process is comprised of:


 Program code
 A set of Data
 Stack
 Process control block(PCB) : A number of attributes
describing the state of the process
 identifier, state, priority, program counter, memory pointers,
context data, I/O status information, accounting information ….
 Contains sufficient information so it is possible to interrupt a
running process and later resume execution as if the interruption
had not occurred
 Created and manager by OS
4

Address Main Memory Program Counter


0
8000
100
Dispatcher

Dispatcher
5000
Process A

 Program that switches the


8000
processor from one process
Process B to another

12000
 Prevents a single process
from monopolizing
Process C processor time

Figure 3.2 Snapshot of Example Execution (Figure 3.4)


at Instruction Cycle 13
5

1 5000 27 12004
5000 8000 12000 2 5001 28 12005
5001 8001 12001 3 5002 -------------------- Timeout
4 5003 29 100
5002 8002 12002 5 5004 30 101
5003 8003 12003 6 5005 31 102
5004 12004 -------------------- Timeout 32 103
7 100 33 104
5005 12005 8 101 34 105
5006 12006 9 102 35 5006
5007 12007 10 103 36 5007
11 104 37 5008
5008 12008 12 105 38 5009
5009 12009 13 8000 39 5010
5010 12010 14 8001 40 5011
15 8002 -------------------- Timeout
5011 12011 16 8003 41 100
(a) Trace of Process A (b) Trace of Process B (c) Trace of Process C ----------------I/O Request 42 101
17 100 43 102
5000 = Starting address of program of Process A 18 101 44 103
19 102 45 104
8000 = Starting address of program of Process B 20 103 46 105
12000 = Starting address of program of Process C 21 104 47 12006
22 105 48 12007
23 12000 49 12008
24 12001 50 12009
25 12002 51 12010
Figure 3.3 Traces of Processes of Figure 3.2 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


6
A Five-State Model

 New : a process has not yet been loaded into main


memory, although its process control block has
been created
 Running
 Not Running
 Ready : ready to execute
 Blocked/Waiting : waiting for I/O
 Exit : the tables and other information associated
with the process are temporarily preserved by the
OS
7

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


8
Five-State Process Model

Dispatch
Admit Release
New Ready Running Exit
Timeout

Event
Occurs Event
Wait

Blocked

Figure 3.6 Five-State Process Model


9
Single Blocked Queue
10
Multiple Blocked Queues
11
Need for Swapping

 Processor is so much faster than I/O that it will be common for


all of the processes in memory to be waiting for I/O
 When none of the processes in main memory is in the Ready
state, the OS swaps these processes to disk to free up more
memory
 Blocked state becomes suspend state when swapped to disk
 Two new states
 Blocked/suspend
 Ready/suspend
t
ai
Occurs
e

Event
at

tW
iv
ct

en
A

Ev
Suspend 12
Process State Transition Diagram
Suspend Blocked

with Two Suspend States


(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


13
Reasons for Process Suspension
14
Process Description

 Operating System Control Structure


 Information about the current status of each process
and resource
 Tables are constructed for each entity the operating
system manages
 Memory Table
 I/O Table
 File Table
 Process Table
15

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


16
Memory Tables

 Allocation of main memory to processes

 Allocation of secondary memory to processes

 Protection attributes for access to shared memory


regions

 Information needed to manage virtual memory


17
I/O Tables

 I/O device is available or assigned

 Status of I/O operation

 Location in main memory being used as the source


or destination of the I/O transfer
18
File Tables

 Existence of files

 Location on secondary memory

 Current Status

 Attributes
19
Primary Process Table

 Attributes necessary for process management

 Process ID

 A pointer to a process image

 Location in memory
20
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).
21
Process Control Block

 Process Identification :

 Process Identifier
 Parent Process Identifier
 User Identifier
22
Process Control Block (2)

 Processor State Information :

 User-Visible Registers
 Control & Status Registers
 Program counter
 Program status word (PSW)
 Stack Pointers
23
Process Control Block (3)

 Process Control Information

 scheduling and state information


 memory management
 resource ownership and utilization
 inter-process communication
 process privileges
 data structuring
24
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


25
Typical Functions of an
Operating System Kernel
Process Management

•Process creation and termination


•Process scheduling and dispatching
•Process switching
•Process synchronization and support for interprocess communication
•Management of process control blocks

Memory Management

•Allocation of address space to processes


•Swapping
•Page and segment management

I/O Management

•Buffer management
•Allocation of I/O channels and devices to processes

Support Functions

•Interrupt handling
•Accounting
•Monitoring
26
Process Creation

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
27
Process Switching

 A running process is interrupted and the OS assigns


another process to the Running state and turns
control over to that process.

 When to switch processes

 process switching vs mode switching


28
When to Switch Processes
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

 Interrupt
 Clock interrupt ( ready state)
 I/O interrupt (running state /  ready state)
 Memory Fault ( blocked state)
 Trap ( exit state /  running state)
 Supervisor call ( blocked state)
29
Processor Execution Mode

 User Mode
 Less-privileged mode
 User programs typically execute in this mode

 Kernel Mode = System Mode = Control Mode


 More-privileged mode
 Kernel of the operating system
30
Mode Switching vs. Process
Switching

 Mode switching :
 User mode (A)  Kernel mode  User mode (A)

 Process switching :
 User mode (A)  Kernel mode  User mode (B)

 (참고) Context switching


31
Change of Process State

update the
move the process
save the context of process control
control block of this
the processor block of the
process to the
process currently in
appropriate queue
the Running state

select another
process for
execution

restore the context


of the processor to
that which existed at
the time the update memory
selected process update the process
management data control block of the
was last switched structures
out process selected
32
Execution of Operating System

 Non-process Kernel
 execute kernel outside of any process
 operating system code is executed as a separate entity
that operates in privileged mode
33
Execution of Operating System (2)

 Execution Within User Processes


 execute operating system software within context of a
user process
 process executes in privileged mode when executing
operating system code
34
Process
Identification

Processor State Process Control


Information Block

Process Control
Information

User Stack

Private User
Address Space
(Programs, Data)

Kernel Stack

Shared Address
Space

Figure 3.16 Process Image: Operating System


Executes Within User Space
35
Execution of Operating System (3)

 Process-Based Operating System


 major kernel functions are separate processes
 Useful in multi-processor or multi-computer environment
36
UNIX SVR4 Process Management

 Most of the OS executes within the environment of a


user process

 Two categories of processes :


 System Process
 0 : Swapper
 1 : init
 Process Tree

 User Process
37
Process Description

User Level System Level


Register Context
Context Context

► Process text ► Program counter ► Process table


entry
► Process data ► Processor status
register ► U(user) area
► User stack
► Stack pointer ► Per process region
► Shared memory
table
► General-purpose
registers ► Kernel stack
38
UNIX Process State Transition Diagram
fork

Created
Preempted

return enough not enough memory


to user memory (swapping system only)

User
Running preempt
swap out
return Ready to Run Ready to Run
reschedule
In Memory Swapped
process swap in
system call,
interrupt Kernel
Running

sleep wakeup wakeup


interrupt,
interrupt return exit

Asleep in swap out Sleep,


Zombie
Memory Swapped

Figure 3.17 UNIX Process State Transition Diagram

You might also like