April 27



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

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

Balance keeping all parts of the system busy AAMIR ABRO Page 4 .6. for an average wait of 4. B. Policy enforcement seeing that stated policy is carried out . Initially. As a counterexample. 3. C. A has an average wait of 4. 1. E. with run times of 2. Using shortest job first we will run the jobs in the order A. consider five jobs. D.LAB REPORT # 6 SHORTEST JOB FIRST SCHEDULING OUTPUT OBSERVATIONS It is worth pointing out that shortest job first is only optimal when all the jobs are available simultaneously. and 3. 0. A through E. only A or B can be chosen. running them in the order B. 1. 4. and 1. respectively. since the other three jobs have not arrived yet. C. E. D. 3. Their arrival times are 0. CONCULSION    Fairness giving each process a fair share of the CPU. However.4.

Sign up to vote on this title
UsefulNot useful