Beruflich Dokumente
Kultur Dokumente
Module-2
by
S Pramod Kumar
Assistant Professor,
Dept.of ECE,KIT,
Tiptur
OS View of Processes
PCB
Fundamental State Transitions,
Threads, Kernel and User level Threads,
Non-preemptive scheduling- FCFS and SRN
Preemptive Scheduling- RR and LCN
Long term, medium term and short term
scheduling in a time sharing system
2
14-Sep-17 O.S.@K.I.T
1
A program is a set of functions and
procedures
Functions may be separate processes, or they
may constitute the code part of a single process
14-Sep-17 O.S.@K.I.T
2
OS view of a process consists of two parts:
1.Code, data, and stack of the process, and
information concerning memory and other
resources, such as files, allocated to it.
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
3
14-Sep-17
14-Sep-17
4
Context save function:
Saves CPU state in PCB, and saves information
concerning context
Changes process state from running to ready
Scheduling function:
Uses process state information from PCBs to select a
ready process for execution and passes its id to
dispatching function
Dispatching function:
Sets up context of process, changes its state to
running, and loads saved CPU state from PCB into
CPU
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
5
An OS contains two processes P1 and P2, with P2 having a higher priority
than P1. Let P2 be blocked on an I/O operation and let P1 be running. The
following actions take place when the I/O completion event occurs for the
I/O operation of P2:
1. The context save function is performed for P1 and its state is changed to
ready.
2. Using the event information field of PCBs, the event handler finds that the
I/O operation was initiated by P2, so it changes the state of P2 from blocked
to ready.
14-Sep-17 O.S.@K.I.T
6
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
7
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
8
• A system contains two processes P1 and P2, P1 CPU bust time
15msec Followed by I/O operation for 100msec. P2 bust
time 30msec Followed by I/O operation for 60msec
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
9
A thread is an alternative model of program
execution
A process creates a thread through a system
call
Thread operates within process context
Switching between threads incurs less
overhead than switching between processes
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
10
A process context switch involves:
1. saving the context of the process in operation
2. saving its CPU state
3. loading the state of the new process
4. loading its CPU state
A threads is a program execution within the
context of a process; many threads can be
created within the same process
Switching between threads of the same process
involves much less context switching overhead
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
11
14-Sep-17 O.S.@K.I.T
12
Kernel-Level Threads
Threads are managed by the kernel
User-Level Threads
Threads are managed by thread library
Hybrid Threads
Combination of kernel-level and user-level
threads
14-Sep-17 O.S.@K.I.T
13
Fast thread switching because kernel is not involved
Blocking of a thread, blocks all threads of the process
Threads of a process: No concurrency or parallelism
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
14
A process is a model of execution of a
program
Can create other processes by making requests to
the OS through system calls
▪ Each of these processes is called its child process
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
15
A thread is an alternative model of execution of
a program
Overhead of switching between threads is much less
than the overhead of switching between processes
Three models of threads:
Kernel-level threads
User-level threads
Hybrid threads
Thread models have different implications for
switching overhead, concurrency, and
parallelism
14-Sep-17 O.S.@K.I.T
14-Sep-17 O.S.@K.I.T
16
Scheduling Terminology and Concepts
• Scheduling is the activity of selecting the next
request to be serviced by a server
– In an OS, a request is the execution of a job or a
process, and the server is the CPU
O.S.
K.I.T.
O.S.
K.I.T.
17
• Turnaround time (ta) Time between the submission of a job
or process and its completion by the system. This concept is
meaningful for noninteractive jobs or processes only.
O.S.
K.I.T.
O.S.
K.I.T.
18
O.S.
K.I.T.
FCFS Scheduling
O.S.
K.I.T.
19
Shortest Request Next (SRN)
Scheduling
May cause
starvation of
long processes
O.S.
K.I.T.
20
O.S.
K.I.T.
O.S.
K.I.T.
21
Example: Variation of Response Time
in RR Scheduling
• rt for a request may be higher for smaller
values of δ
Time slice 5 ms 10 ms 15 ms 20 ms
Average rt for subsequent subrequest (ms) 280 240 240 220
O.S.
K.I.T.
Issues:
- Short processes will finish
ahead of long processes
- Starves long processes of
CPU attention
- Neglects existing processes
if new processes keep
arriving in the system
O.S.
K.I.T.
22
Scheduling in Practice
• To provide a suitable combination of system
performance and user service, OS has to adapt its
operation to the nature and number of user
requests and availability of resources
– A single scheduler using a classical scheduling policy
cannot address all these issues effectively
• Modern OSs employ several schedulers
– Up to three schedulers
• Some of the schedulers may use a combination of
different scheduling policies
O.S.
K.I.T.
23
Example: Long, Medium-, and Short-
Term Scheduling in Time-Sharing
O.S.
K.I.T.
24