Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 38

Operating

Systems
Dr Damitha Karunaratna
University of Colombo school of computing
Topics to discuss
• What is a process
• Difference between a process and a program
• Process creation and termination
• Process hierarchy
• Uniprocessor scheduling
• Process schedulers
• Queuing diagram for scheduling
• Seven state transition diagram
• Context switching
• Threads

Operating Systems 2
Processes
 Process is a fundamental concepts in modern operating systems.
 It was first introduced by the designers of Multics operating systems
in the 1960s.
 The programs that reside in main memory are absolutely different
from their counter-parts the program files on hard disks or any other
secondary storage devices.

Operating Systems 3
Process and a program
• A process is a program in execution
• An instance of a program running on a computer.
• The entity that can be assigned to and executed
on a processor
• A program is a static set of instructions

Operating Systems 4
Process and a program
• A process exists in a limited span of time. Two or
more processes could be executing the same
program, each using their own data and
resources.
• A program is a static entity made up of
instructions. A program exists in the secondary
storage till it is deleted. A program does not
perform the action by itself.

Operating Systems 5
Process creation and termination
• When a new process is created, the operating system
builds the date structures that are used to manage the
process and allocates space in main memory to the
process.
• A process may terminates in a number of ways.
• After completion of the instructions.
• User terminates (kills) the process explicitly. For
example clicking on the cross button in the windows
applications.
• A process may terminate due to abnormal condition.
• When a process finishes, the operating system will free
the memory space it occupies and remove the data
structures it allocated to manage the process.
Operating Systems 6
Processes in a typical Linux
system

Operating Systems 7
Uniprocessor Scheduling
Type of processes
• I/O bound processes
• Processor bound processes

Operating Systems 8
Uniprocessor Scheduling
Types of Scheduling
•Long-term scheduling(Job scheduling) : It determines which
programs are admitted to the system for processing. Job
scheduler selects processes from the queue and loads them
into memory for execution. Process loads into the memory
for CPU scheduling.
•Medium-term scheduling : Medium term scheduling is in
charge of swapping processes between the main memory
and the secondary storage.
•Short-term scheduling (low-level scheduling) : Determines
which ready process will be assigned the CPU when it next
becomes available.

Operating Systems 9
Scheduling Policies
◦ Non-preemptive
◦ Once a process is in the running state, it will
continue until it terminates or blocks itself for
I/O.
◦ Preemptive
◦ Currently running process may be interrupted
and moved to the Ready state by the OS.
◦ Allows for better service since any one process
cannot monopolize the processor for very long

Operating Systems 10
Processor Scheduling
Assigning the processor to the processes.
Turnaround time : Time required for a particular process to complete,
from submission time to completion.
Response time : The time taken in an interactive program from the
issuance of a command to the commence of a response to that
command.
Throughput : Number of processes completed per unit time. May range
from 10 / second to 1 / hour depending on the specific processes.
Waiting time : How much time a process spends in the ready queue
waiting its turn to get on the CPU.

Operating Systems 11
Long-term scheduling(Job
scheduling)
• Determines which processes are admitted to the
system for processing
• Controls the degree of multiprogramming
• If more processes are admitted
• better CPU usage
• less likely that all processes will be blocked
• The long term scheduler may attempt to keep a
mix of processor-bound and I/O-bound processes

Operating Systems 12
Medium-Term Scheduling
• Swapping decisions based on the need to manage
multiprogramming
• Done by memory management software

Operating Systems 13
Logical view of swapping

http://cs.uttyler.edu/Faculty/Rainwater/COSC3355/Animations/backingstore.htm

Operating Systems 14
Short-Term Scheduling
• Determines which process is going to execute next
(also called CPU scheduling)
• The short term scheduler is known as the
dispatcher
• Dispatching the CPU to the process

Operating Systems 15
Schedulers - Comparison
Long Term Scheduler Short Term Scheduler Medium Term Scheduler
Job Scheduler CPU scheduler Processes swapping
scheduler
Selects processes from a Selects those processes Swapped out/Re-
pool and loads them into which are ready to introduces the processes
the memory for execute for dispatching into memory and
execution execution can be
continued.
Controls the degree of Provides lesser control Controls the degree of
multiprogramming over the degree of multiprogramming
multiprogramming
Speed is lesser than Speed is fastest among Speed is in between
short term scheduler other two (short and long term
schedulers)

Operating Systems 16
Queuing Diagram for Scheduling

Operating Systems 17
Seven state process transition
Diagram
Typically, new
processes are not in the
main memory.

http://williamstallings.com/OS/Animation/Queensland/PROCESS.SWF

Operating Systems 18
Seven state process transition
Diagram

Long Term
Medium
Scheduler
Term Short Term
Scheduler Scheduler

Operating Systems 19
Process Control Block (PCB)
All of the information needed to keep track of a process
when switching states is kept in a data package called a
process control block. The process control block typically
contains:
•An ID number that identifies the process
•Pointers to the locations in the program and its data where processing
last occurred
•Register contents
•States of various flags and switches
•A list of files opened by the process
•The priority of the process
•The status of all I/O devices needed by the process

Operating Systems 20
Context Switching
• A context switch is the mechanism to store and restore the state or
context of a CPU in Process Control block so that a process execution
can be resumed from the same point at a later time.
• Using this technique a context switcher enables multiple processes to
share a single CPU. Context switching is an essential part of a
multitasking operating system features.
• When the scheduler switches the CPU from executing one process to
execute another, the context switcher saves the content of all
processor registers for the process being removed from the CPU, in its
process control block.
• Context switch time is pure overhead.
• Context switching can significantly affect performance as modern
computers have a lot of general and status registers to be saved.

Operating Systems 21
Context Switching

Operating Systems 22
Short-term scheduling algorithms
• First-come-first served
• Round Robin
• Shortest Process next

Operating Systems 23
Objectives of Short-Term
Scheduling
User-oriented
◦ Response Time: Elapsed time from the
submission of a request to the beginning of
response
◦ Turnaround Time: Elapsed time from the
submission of a process to its completion
System-oriented
◦ processor utilization
◦ fairness
◦ throughput: number of process completed per
unit time

Operating Systems 24
First-come-first served
scheduling
• Each process joins the end of the Ready queue.
• When the current process ceases to execute, the
process waited the longest time in the Ready
queue is assigned the CPU.

Operating Systems 25
Example - FCFS
Process Arrival Service Finish Turnaround
Time Time time time Average Turnaround time
A 0 3 3 3 = (3 + 7+ 9+ 12 + 12)/5
B 2 6 9 7 = 8.60
C 4 4 13 9
D 6 5 18 12
E 8 2 20 12

Operating Systems 26
Shortest Job First
(Shortest Process Next)
• Nonpreemptive policy
• Process with shortest expected processing time is
selected next
• Short process jumps ahead of longer processes

Operating Systems 27
Shortest Job First
(Shortest Process Next)
Process Arrival Service Finish Turnaround
Time Time time time Average Turnaround time
A 0 3 3 3 = (3 + 7+ 11+ 14 + 3)/5
B 2 6 9 7 = 7.60
C 4 4 15 11
D 6 5 20 14
E 8 2 11 3

Operating Systems 28
FCFS - Issues
A short process may have to wait a very
long time before it can execute
Favors CPU-bound processes
◦ I/O processes have to wait until CPU-
bound process completes

Operating Systems 29
Round Robin Scheduling
• Clock interrupt is generated at periodic intervals.
• When an interrupt occurs, the currently running
process is placed in the ready queue
(preempted)
• Next process in the ready queue is assigned the
CPU.
• Known as time slicing

Operating Systems 30
Queuing Diagram

Operating Systems 31
Round Robin Scheduling
Scheduling Policy – Preemption, Time quantum for each process = 1
Process Arrival Service Finish Turnaround Average Turnaround time
Time Time time time
= (4 + 16+ 13+ 14 + 7)/5
A 0 3 4 4
= 10.80
B 2 6 18 16
C 4 4 17 13
D 6 5 20 14
E 8 2 15 7

0 5 10 15 20

Operating Systems 32
Round Robin Scheduling
Scheduling Policy – Preemption, Time quantum for each process = 4
Process Arrival Service Finish Turnaround Average Turnaround time
Time Time time time
= ( 3+ 15+ 7+ 14 + 11)/5
A 0 3 3 3
= 10.00
B 2 6 17 15
C 4 4 11 7
D 6 5 20 14
E 8 2 19 11

Gantt Chart ?

Operating Systems 33
Priority Scheduling
• Scheduler will always choose a process of higher
priority over one of lower priority
• Use multiple ready queues to represent multiple
levels of priority
• Lower-priority may suffer starvation
• Allow a process to change its priority based on its age or
execution history

Operating Systems 34
Priority Queuing

Can be either preemptive or non-preemptive

Operating Systems 35
Threads
A thread is the smallest schedulable unit in a system that can be
managed independently by an operating system. A thread can also be
viewed as an execution streams within a single process. Generally a
thread contained inside a process. It is possible to have processes with
one threads or processes with multiple threads.
All threads of a process share common code, data, and other
resources, including CPU registers.
• Allows multiple tasks to be performed simultaneously in a single address
space.
• Context switching generates less overhead.

Operating Systems 36
Threads …..
Threads are very useful whenever a process has multiple tasks to
perform independently of the others.
For example in a word processor, a background thread may check
spelling of a document while a foreground thread processes user
keystrokes, while another thread may automatically backs up the
edited section periodically.

Operating Systems 37
Topics discussed
• What is a process
• Difference between a process and a program
• Process creation and termination
• Process hierarchy
• Uniprocessor scheduling
• Process schedulers
• Queuing diagram for scheduling
• Seven state transition diagram
• Context switching
• Threads

Operating Systems 38

You might also like