Ch. 4 ... Part - 1
Ch. 4 ... Part - 1
Ch. 4 ... Part - 1
System
CH. 4 Services
BY DR. VEEJYA KUMBHAR
“UNIX is basically a simple operating system, but you
have to be a genius to understand the simplicity.”
Dennis Ritchie
(1941–2011)
5 W’s of Unix Operating System
What – Unix is first multiuser, multitasking and
multithreading operating system.
When – Developed in 1969.
Where – @ AT&T’s Bell Laboratory, USA.
Who – By Dennis Richie, Kenneth Thompson
Why – to develop the operating system
designed to run on computers of all
sizes, making open systems possible.
Ch. 4 Operating System Services
Syllabus
• Processes
• Process Structure
• Process Scheduling
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Process
Definitions:
A process is basically a program in execution.
The process is not as same as program code but a lot more than it.
A process is an 'active' entity as opposed to the program which is considered
to be a 'passive' entity.
Attributes held by the process include hardware state, memory, CPU, etc.
E.g. .c, .cpp, .java , .py are the programs. When we double click on .exe or
type as ./a.out…the code gets occupied by some space in memory.
Process Vs Program
Process Program
A Program is basically a collection of
The process is basically an instance of
instructions that mainly performs a
the computer program that is being
specific task when executed by the
executed.
computer.
A process has a shorter lifetime. A Program has a longer lifetime.
A Process requires resources such as A Program is stored by hard-disk and
memory, CPU, Input-Output devices. does not require any resources.
A process has a dynamic instance of A Program has static code and static
code and data data.
Basically, a process is the running On the other hand, the program is
instance of the code. the executable code.
Process States
A mode switch occurs when the CPU privilege level is changed, for example
when a system call is made, or a fault occurs.
The kernel works in more a privileged mode than a standard user task.
If a user process wants to access things that are only accessible to the kernel,
a mode switch must occur.
The currently executing process need not be changed during a mode switch.
A mode switch typically occurs for a process context switch to occur.
Only the kernel can cause a context switch.
CPU-Bound vs I/O-Bound Processes
A CPU-bound process requires more CPU time or spends more time in the
running state.
An I/O-bound process requires more I/O time and less CPU time.
• Processes ✓
• Process Structure
• Process Scheduling
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Process Structure
Process Structure
• Processes ✓
• Process Structure ✓
• Process Scheduling
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Multiprogramming
➢ When there are two or more runnable processes then it is decided by the Operating
system which one to run first then it is referred to as Process Scheduling.
➢ A scheduler is used to make decisions by using some scheduling algorithm.
➢ Given below are the properties of a Good Scheduling Algorithm:
• Response time should be minimum for the users.
• The number of jobs processed per hour should be maximum i.e Good
scheduling algorithm should give maximum throughput.
• The utilization of the CPU should be 100%.
• Each process should get a fair share of the CPU.
Process Scheduling
Process scheduling is the activity of the process manager that handles the removal of
the running process from the CPU and the selection of another process based on a
particular strategy.
Process scheduling is an essential part of a Multiprogramming operating system.
Such operating systems allow more than one process to be loaded into the executable
memory at a time and the loaded process shares the CPU using time multiplexing.
• All processes, upon entering into the system, are stored in the Job
Queue.
Scheduling Queues
• Processes in the Ready state are placed in the Ready Queue.
• Processes waiting for a device to become available are placed in Device
Queues. There are unique device queues available for each I/O device.
• A new process is initially put in the Ready queue. It waits in the ready
queue until it is selected for execution(or dispatched).
• Once the process is assigned to the CPU and is executing, one of the
following several events can occur:
• The process could issue an I/O request, and then be placed in the I/O queue.
• The process could create a new subprocess and wait for its termination.
• The process could be removed forcibly from the CPU, as a result of an interrupt,
and be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state to the ready state, and is then put back in the
ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB
and resources deallocated.
Types of Schedulers:
1. Long term – performance – Decides about how many processes should be made to stay in
the ready state, this decides the degree of multiprogramming. Once a decision is taken it
lasts for a long time hence called long term scheduler.
2. Short term – Context switching time – Short term scheduler will decide which process to
be executed next and then it will call dispatcher. A dispatcher is a software that moves
process from ready to run and vice versa. In other words, it is context switching.
3. Medium term – Swapping time – Suspension decision is taken by medium term scheduler.
Medium term scheduler is used for swapping that is moving the process from main
memory to secondary and vice versa.
Long Term or job scheduler:
Long Term
Schedular
Short-term or CPU scheduler:
It is responsible for selecting one process from the ready state for
scheduling it on the running state.
Note:
• Short-term scheduler only selects the process to schedule it doesn’t
load the process on running.
• The CPU scheduler is responsible for ensuring there is no starvation
owing to high burst time processes.
Short-term or CPU scheduler:
1. Switching context.
2. Switching to user mode.
3. Jumping to the proper location in the newly loaded program.
Short Term
Schedular
Dispatcher
Dispatcher
Medium-term scheduler:
• Processes ✓
• Process Structure ✓
• Process Scheduling ✓
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Scheduling Algorithms
❑ FCFS (Non-pre-emptive)
❑ SJF ( Pre-emptive and Non-pre-emptive)
❑ Priority ( Pre-emptive and Non-pre-emptive)
❑ Round-Robin ( Pre-emptive)
❑ Multilevel Queue ( Pre-emptive)
❑ Multilevel Feedback Queue( Pre-emptive)
Choosing a scheduling algorithm
Burst Time
Every process in a computer system requires some amount of time for its execution. This
time is both the CPU time and the I/O time. The CPU time is the time taken by CPU to
execute the process. While the I/O time is the time taken by the process to perform some
I/O operation. In general, we ignore the I/O time and we consider only the CPU time for a
process. So, Burst time is the total time taken by the process for its execution on the
CPU.
Arrival time
Arrival time is the time when a process enters into the ready state and is ready for its
execution.
Here in the above example, the arrival time of all the 3 processes are 0 ms, 1 ms, and 2 ms respectively.
Exit time is the time when a process completes its execution and exit from the system.
Gantt Chart
Response Time
Waiting Time
Turnaround Time
Throughput
CPU Utilization
Metrics to evaluate algorithm performance
Response Time
The first response time when the process gets selected
for execution.
Waiting Time
The total time process has spent in the system sitting idle.
Metrics to evaluate algorithm performance
Turnaround Time
It is the total time a process has spent in the system(including burst
time, CPU time, I/O time , waiting time etc.)
Throughput
It is the total no. of processes completed in one unit of time.
CPU Utilization
It is measured as how much time the CPU is busy in executing the
processes.
1. First Come First Serve:
FCFS considered to be the simplest of all operating system scheduling algorithms. First
come first serve scheduling algorithm states that the process that requests the CPU
first is allocated the CPU first and is implemented by using FIFO queue.
Characteristics of FCFS:
•FCFS supports non-preemptive CPU scheduling algorithms.
•Tasks are always executed on a First-come, First-serve concept.
•FCFS is easy to implement and use.
•This algorithm is not much efficient in performance, and the wait time is quite high.
1. First Come First Serve:
Advantages of FCFS:
• Easy to implement
• First come, first serve method
Disadvantages of FCFS:
FCFS suffers from Convoy effect.
The average waiting time is much higher than the other algorithms.
FCFS is very simple and easy to implement and hence not much efficient.
Convoy Effect in OS
Convoy Effect is phenomenon associated with the First Come First Serve
(FCFS) algorithm, in which the whole Operating System slows down due
to few slow processes.
FCFS algorithm is non-preemptive in nature, that is, once CPU time has been
allocated to a process, other processes can get CPU time only after the current
process has finished. This property of FCFS scheduling leads to the situation
called Convoy Effect.
Ex. 1 Schedule following processes using FCFS algorithm
and Calculate response time, waiting time, turnaround
time, completion time of all the processes. Also Calculate
average turnaround time, average waiting time ,
throughput, and CPU utilization.
0 ms
P1
0 ms 8 ms
P1 P2
0 ms 8 ms 15 ms
P1 P2 P3
0 ms 8 ms 15 ms 25 ms
Process Arrival Time Burst Time Response Time Competition Turnaround Waiting
Time Time Time
P1 0 8 0 8 8-0 = 8 8-8 = 8
P2 0 7 8 15 15-0= 15 15-7 = 8
P3 2 10 15 25 25-2 = 23 23-10 = 13
Turnaround Time = Completion Time – Arrival Time
Waiting Time = Turnaround Time – Burst Time