Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Shortest Job First Scheduling Lr#6 by Aamir Abro

# Shortest Job First Scheduling Lr#6 by Aamir Abro

Ratings: (0)|Views: 608 |Likes:
This is my Operating Systems Lab Report while doing Computer Systems Engineering From EME college, NUST.
This is my Operating Systems Lab Report while doing Computer Systems Engineering From EME college, NUST.

### Availability:

See more
See less

06/21/2013

pdf

text

original

LABREPORT# 6
April 27
2010
BY AAMIR ABRO || TO SIR QASIM

SHORTEST JOBFIRSTSCHEDULING

LAB REPORT # 6 SHORTEST JOB FIRST SCHEDULING
AAMIR ABRO

Page 2
OBJECT
To Study and write algorithm for Shortest Job First scheduling.
Shortest Job First scheduling is nonpreemptive batch algorithm that assumes the run times areknown in advance. In an insurance company, for example, people can predict quite accuratelyhow long it will take to run a batch of 1000 claims, since similar work is done every day. Whenseveral equally important jobs are sitting in the input queue waiting to be started, the schedulerpicks the shortest job first. Here we find four jobs A, B, C, and D with run times of 8, 4, 4, and 4minutes, respectively. By running them in that order, the turnaround time for A is 8 minutes, forB is 12 minutes, for C is 16 minutes, and for D is 20 minutes for an average of 14 minutes.Now let us consider running these four jobs using shortest job first. The turnaround times arenow 4, 8, 12, and 20 minutes for an average of 11 minutes. Shortest job first is provably optimal.Consider the case of four jobs, with run times of a, b, c, and d, respectively. The first job finishesat time a, the second finishes at time a + b, and so on. The mean turnaround time is (4 a + 3 b + 2c + d) / 4. It is clear that a contributes more to the average than the other times, so it should bethe shortest job, with b next, then c, and finally d as the longest as it affects only its ownturnaround time. The same argument applies equally well to any number of jobs.An example of shortest job first scheduling. (a) Running four jobs in the original order. (b)Running them in shortest job first order.
Source code for SHORTEST JOB FIRST SCHEDULING Dispalaying AWT and Processes in theorder they are executed
// abro.cpp : Defines the entry point for the console application.# include <iostream>using namespace std;struct process{int btime;char name;};

LAB REPORT # 6 SHORTEST JOB FIRST SCHEDULING
AAMIR ABRO

Page 3
void main (){int p;float awt=0;cin >> p;process * pr = new process[p];for (int i =0 ; i <p ;i++){cout << "Enter Process name in Char : ";cin >> pr[i].name;cout << "Enter Process brust time : ";cin >> pr[i].btime;cout << endl;}process temp;for (int k =1 ; k<p-1 ;k++){for (int j =0 ; j<p-1 ;j++){if (pr[j+1].btime < pr[j].btime ){temp = pr[j];pr [j] = pr [j+1];pr [j+1] = temp;}}}for (int m=0 ; m<p ; m++){cout << pr[m].name << " " << pr[m].btime <<endl ;}for (int n=0 ; n<p-1 ; n++){awt += pr[n].btime;}awt = awt / (float) p;cout << "the awt is : "<< awt ;}