Title: CPU Scheduling: Types of Scheduling: Long Term Scheduling: Medium Term Scheduling Short Term Scheduling
Title: CPU Scheduling: Types of Scheduling: Long Term Scheduling: Medium Term Scheduling Short Term Scheduling
Title: CPU Scheduling: Types of Scheduling: Long Term Scheduling: Medium Term Scheduling Short Term Scheduling
Assignment Statement:
Write a menu driven program to implement following CPU scheduling algorithms
1) First come First Serve (FCFS)
2) Shortest Job First (SJF) (Preemptive)
Objectives:
To study the Need for CPU scheduling
To do the comparative study of various CPU scheduling methods
Implementation of CPU Scheduling
Theory:
Need: In multiprogramming environment, multiple processes are maintained in
the main memory. Each process alternates between the using a processor and
waiting for I/O to be completed or for some other event to occur. The processor is
kept busy by executing one process while others wait. The key to
multiprogramming is Scheduling. The aim of Processor scheduling is to assign
processes to be executed by the processor over time, in such a way that meets the
system objectives, such as response time, throughput and processor efficiency.
Types of Scheduling:
Long Term Scheduling: It is invoked when new process is created. This
decides whether to add a new process to the set/pool of processes that are
currently active. It controls the degree of multiprogramming
Medium Term Scheduling: It is a part of swapping function. The decision is
taken whether to add a process to those that are partially or fully available in
memory and therefore available for execution.
Short Term Scheduling: It is the actual decision of which ready processes will
be executed by the processor. CPU Scheduling comes under short term scheduling
Characteristics:
Selection Function: max(w), selects the process which is waiting in the
ready queue for maximum time.
Decision Mode: Non_preemptive
Throughput: Not emphasized
Response Time: May be high, especially if there is a large variance in the
process Execution times.
Overhead: Minimum
Effect on Processes: Penalizes short and I/O bound processes.
Starvation: No
2) Shortest Job First (SJF) Preemptive or Shortest Remaining Time: It is a
preemptive version of SJF. In this policy, scheduler always chooses the process
that has the shortest expected remaining processing time. When a new process
arrives in the ready queue, it may in fact have a shorter remaining time than the
currently running process. Accordingly, the scheduler may preempt whenever a
new process becomes ready. Scheduler must have an estimate of processing time
to perform the selection function.
Characteristics:
Selection Function: minimum total service time required by the process,
minus time spent in execution so far.
Decision Mode : Preemptive ( At arrival time)
Throughput: High
Response Time: Provides good response time
Overhead: Can be high
Effect on Processes: Penalizes long processes.
Starvation: Possible
Data Structure Used:- Array of structures, having following fields in
structure:
Process_no, Arrival_time, Burst_Time, Waiting_time,
Turnaround_time
Algorithm: FCFS
1. Read total no of processes (n)
2. For reach process read arrival time and burst or service time.
10. Stop
Output
Gant Chart
0----P0---3P14--P2--6IDLE7-----P3----11-P4-13
Process AT BT WT TAT
P0 0 3 0 3
P1 1 1 2 3
P2 2 2 2 4
P3 7 4 0 4
P4 8 2 3 5
SJF-Preemptive Input
Process AT BT
P0 0 3
P1 1 1
P2 2 2
P3 7 4
P4 8 2
Output
Gant Chart
0P01P12P04P26IDLE7P38-P4-10P313
Process AT BT WT TAT
P0 0 3 1 4
P1 1 1 0 1
P2 2 2 2 4
P3 7 4 2 6
P4 8 2 0 2
Platform :- LINUX
FAQ’s :-