LAB REPORT #7

April 27

2010
PREEMPTIVE SHORTEST JOB FIRST SCHEDULING

BY AAMIR ABRO || TO SIR QASIM

LAB REPORT # 7

PREEMPTIVE SHORTEST JOB FIRST SCHEDULING

OBJECT
To Study and write algorithm for Preemptive Shortest Job First scheduling.

TASK

P

reemptive version of shortest job first is shortest remaining time next. With this algorithm, the scheduler always chooses the process whose remaining run time is the shortest. Again here, the run time has to be known in advance. When a new job arrives, its total time is compared to the current process' remaining time. If the new job needs less time to finish than the current process, the current process is suspended and the new job started. This scheme allows new short jobs to get good service.

Source code for SHORTEST JOB FIRST SCHEDULING Dispalaying AWT(which is a little wrong) and Processes in the order they are executed
/* * File: main.cpp * Author: abro * * Created on April 27, 2010, 12:55 PM */ # include <iostream> using namespace std; struct process { char name ; int bt; int at; int wait; }; int main() { int sjob=0; int size=0; int clock = 0 ; cout << "enter no of the processes : "; cin >> size ; process * rqueue = new process [size] ; for (int x=0 ; x<size ; x++){ cout << "Enter Process name in one Char cin >> rqueue[x].name; cout << "Enter brust time : "; cin >> rqueue[x].bt; cout <<"Enter Arival time : "; cin >> rqueue[x].at; : ";

AAMIR ABRO

Page 2

LAB REPORT # 7
rqueue[x].wait = 0; } for ( ; true ; ){ bool end = true; for (int a=0 ; a <size ; a++){ if (rqueue[a].bt !=0) end = false ; } if (end == true ) break;

PREEMPTIVE SHORTEST JOB FIRST SCHEDULING

if (rqueue[sjob].bt == 0) { for (int x=0 ; x<size ; x++) { if (rqueue[x].bt != 0) { sjob = x; break; } } } for (int y=0 ; y<size ; y++){ if (rqueue[y].at <=clock ) if (rqueue[y].bt != 0) if (rqueue[y].bt <= rqueue[sjob].bt ) sjob = y; } rqueue[sjob].bt--; cout << rqueue[sjob].name << " clock ++;

";

for(int z=0 ; z <size ; z++) { if (z != sjob) if (rqueue[z].bt !=0) if (rqueue[z].at <= clock ) rqueue[z].wait++; } } float awt =0; for (int t=0 ; t <size ; t++ ) { awt += (float)rqueue[t].wait; } awt = awt / (float) size ; cout <<endl <<"the average waiting time is" return 0; }

<<awt <<endl;

AAMIR ABRO

Page 3

LAB REPORT # 7

PREEMPTIVE SHORTEST JOB FIRST SCHEDULING

OUTPUT

OBSERVATIONS
It is worth pointing out that preemptive shortest job first is only optimal when all the jobs are available with different arrival times.

CONCULSION
Preemptive Shortest Job First Scheduling can be concluded as that we should use it if we want:    Fairness giving each process a fair share of the CPU. Policy enforcement seeing that stated policy is carried out. Balance keeping all parts of the system busy

AAMIR ABRO

Page 4

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.