You are on page 1of 16

Operating Systems Laboratory

Title: Non-preemptive First Come First Serve without arrival time

OS-O1a

Aim: Write a program to implement FCFS non-preemptive CPU Scheduling algorithm without arrival time. Algorithm: 1. Start 2. Create a class process with two properties name and bust_time, string and int as data types 3. Read number of processors, as n 4. Create n process using array 5. sum=0 6. for i= 0 to n in steps by 1 6.1. Create p[i] as new process 6.2. Read process name, p[i].name 6.3. Read burst time, p[i].burst_time 7. Write Enter the order of process 8. for i=0 to n-2 in steps by 1 8.1. Read the process name 8.2. j=0 8.3. while(j<n) 8.3.1. if the process name is equals to p[j] name then 8.3.1.1. Write p[j].name 8.3.1.2. sum=sum+p[j].burst_name 8.3.2. Increment j 9. Write Average Waiting Time = ,sum/n 10. Stop Test Data: Input: Number of Process: 4 Process 1:p1 Burst time: 5 Process 2:p2 Burst time: 10 Process 3:p3 Burst time: 15 Process 4:p4 Burst time: 10 Output: Order is p1 p2 p4 p3 Average waiting time: 11.25

Page 1 of 16

Operating Systems Laboratory

Title: Non-preemptive First Come First Serve with arrival time

OS-O1b

Aim: Write a program to implement FCFS non-preemptive CPU Scheduling algorithms with arrival time Algorithm: 1. Start 2. Create a class process with properties name, burst_name, arrival_time as string, int and int as data types 3. Read number of process, as n 4. Create n process using array 5. sum1=0 6. temp=0 7. for i=0 to n-1 in steps by 1 7.1. Create p[i] as new process 7.2. Read process name, p[i].name 7.3. Read burst time, p[i].burst_time 7.4. Read access time, p[i].arrival_time 7.5. sum[i]=0 7.6. num[i]=0 8. for i=0 to n-1 in steps by 1 8.1. for j=0 to n-1 in steps by 1 8.1.1. if p[i].arrival_time > p[j].arrival_time then 8.1.1.1. t=p[j] 8.1.1.2. p[j]=p[i] 8.1.1.3. p[i]=t 9. for i=0 to n-1 in steps by 1 9.1. Write p[i].name 9.2. sum[i]=p[i].burst_time+temp 9.3. temp=sum[i] 10. for i=0 to n-1 in steps by 1 10.1. num[i]=p[i].burst_time+temp 10.2. temp=sum[i] 11. for i=0 to n-1 in steps by 1 11.1. num[i]=sum[i]-p[i].arrival_time 11.2. sum1=sum1+num[i] 12. avg= sum1/n 13. Write Average waiting time = , avg 14. Stop Test Data: Input: Number of process: 3 Process 1: p1 Burst time: 5 Arrival time: 0

Page 2 of 16

Operating Systems Laboratory

Process 2: p2 Burst time: 1 Arrival time: 3 Process 3: p3 Burst time: 3 Arrival time: 1 Output: Order is _ p1, p3, p2 Average waiting time: 7.00

Page 3 of 16

Operating Systems Laboratory

Title: Non-preemptive Shortest Job First without arrival time

OS-O2a

Aim: Write a program to implement SJF non-preemptive CPU Scheduling algorithm without arrival time. Algorithm: 1. Start 2. Create a class process with properties name, burst_name as string, int as data types 3. Read number of process, as n 4. Create n process using array 5. sum1=0 6. temp=1 7. for i=0 to n-1 in steps by 1 7.1. Create new process p[i] 7.2. Read process name, p[i].name 7.3. Read process burst name, p[i].burst_name 7.4. sum[i]=0 8. for i =0 to n-1 in steps by 1 8.1. for j = 0 to n-1 in steps by 1 8.1.1. if p[i].burst_time > p[j].burst_time then 8.1.1.1. t=p[j] 8.1.1.2. p[j]=p[i] 8.1.1.3. p[i]=t 9. for i=1 to n-1 in steps by 1 9.1. Write p[i].name 9.2. sum[i]=temp+p[i].burst_time 9.3. temp=sum[i] 10. for i=0 to n-1 in steps by 1 10.1. sum1 = sum1+sum[i] 11. avg=sum[i]/n 12. Write Average waiting time: ,avg 13. Stop Test Data: Input: Enter number of process: 3 Process 1: p1 Burst time: 3 Process 2: p2 Burst time: 1 Process 3: Burst time: 2 Output: Order by p2, p3, p1

Page 4 of 16

Operating Systems Laboratory


Average waiting time: 1.33334

Page 5 of 16

Operating Systems Laboratory

Title: Non-preemptive Shortest Job First with arrival time

O2a

Aim: Write a program to implement Shortest Job First non-preemptive CPU Scheduling algorithm with arrival time. Algorithm: 1. Start 2. Create a class process with properties name, burst_name, arrival_time as string, int and int as data types 3. Read number of process, as n 4. Create n process using array 5. sum1=0 6. temp=0 7. for i=0 to n-1 in steps by 1 7.1. Create p[i] as new process 7.2. Read process name, p[i].name 7.3. Read burst time, p[i].burst_time 7.4. Read access time, p[i].arrival_time 7.5. sum[i]=0 7.6. num[i]=0 8. for i=0 to n-1 in steps by 1 8.1. Write p[i].name 8.2. sum[i+1]-k+p[i].burst_time 8.3. k=sum=sum[i+1] 8.4. num[i] = sum[i]- p[i].arrival_time 8.5. for j=0 to n-1 in steps by 1 8.5.1. if sum[i+1] >= p[j].burst_time then 8.5.1.1. v=j 8.6. for j =i+1 to v in steps by 1 8.6.1. for s= j to v in steps by 1 8.6.1.1. if p[j].burst_time > p[s].burst_time then 8.6.1.1.1. t= p[j] 8.6.1.1.2. p[j]=p[i] 8.6.1.1.3. p[i]=t 9. sum1=0 10. for i=0 to n-1 in steps by 1 10.1. sum1+=num[i] 11. avg=sum1/n 12. Write Average waiting time = ,avg 13. Stop Test Data Input: Enter number of process: 4

Page 6 of 16

Operating Systems Laboratory


Process 1: p1 Access Time: 4 Arrival Time: 0 Process 2: p2 Access Time: 5 Arrival Time: 1 Process 3: p3 Access Time: 7 Arrival Time: 2 Process 4: p4 Access Time: 3 Arrival Time: 3 Output: Order by_ P1, p4, p2, p3 Average waiting time: 4.25

Page 7 of 16

Operating Systems Laboratory

Title: Non-preemptive Priority with arrival time

OS-O3

Aim: Write a program to implement priority non-preemptive CPU Scheduling algorithm with arrival time. Algorithm: 1. Start 2. Create a Class process with four properties name, arrival_time, burst_time, and priority as string, int, int, and int respectively 3. Read number of process, n 4. Create n process using array 5. for i=0 to n-1 in steps by 1 5.1. Create process p[i] 5.2. Read process name, p[i].name 5.3. Read process burst time, p[i].burst_time 5.4. Read process arrival time, p[i].arrival_time 5.5. Read process priority, p[i].priority 6. for i=0 to n-1 in steps by 1 6.1. for j=0 to n-1 in steps by 1 6.1.1. if p[i].arrival_time > p[i].arrival_time then 6.1.1.1. t= p[j] 6.1.1.2. p[j]=p[i] 6.1.1.3. p[i]=t 7. for i=0 to n-1 in steps by 1 7.1. Write p[i].name 7.2. sum[i+1]=k+ p[i].burst_time 7.3. k=sum[i+1] 7.4. sum[i]=sum[i]- p[i].arrival_time 7.5. for j=0 to n-1 in steps by 1 7.5.1. if sum[i+1] >= p[j].arrival_time then 7.5.1.1. v=j 7.6. for j=i+1 to v in steps by 1 7.6.1. for l=j to v in steps by 1 7.6.1.1. if p[j].priority > p[l].priority then 7.6.1.1.1. t=p[j] 7.6.1.1.2. p[j]=p[l] 7.6.1.1.3. p[l]=t 8. for i=0 to n-1 in steps by 1 8.1. sum2= sum2+sum1[i] 9. avg=sum2/n 10. Write Average waiting time= ,avg 11. Stop Test Data Input: Enter number of process: 5

Page 8 of 16

Operating Systems Laboratory

Process 1: p1 Burst time: 5 Arrival time: 0 Priority : 1 Process 2: p2 Burst time: 7 Arrival time: 1 Priority : 1 Process 3: p3 Burst time: 3 Arrival time: 4 Priority : 2 Process 4: p4 Burst time: 6 Arrival time: 7 Priority : 4 Process 5: p5 Burst time: 1 Arrival time: 2 Priority : 3 Output: Order by p1, p2, p3, p5, p4 Average waiting time: 6.8

Page 9 of 16

Operating Systems Laboratory

Title: Preemptive Shortest Job First

OS-O4

Aim: Write a program to implement the preemptive SJF CPU Scheduling algorithm. Algorithm: 1. Start 2. Create a Class process with four properties name, arrival_time, and burst_time as string, int, and int respectively 3. Read number of process, n 4. Create n process using array 5. for i=0 to n-1 in steps by 1 5.1. Create process p[i] 5.2. Read process name, p[i].name 5.3. Read process burst time, p[i].burst_time 5.4. Read process arrival time, p[i].arrival_time 6. for pos=0 to t<p[n-1] in steps by 1 6.1. if p[index].burst_time > 0 then 6.1.1. order[pos]=p[index].name 6.1.2. p[index].burst_time=p[index].burst_time-1 6.1.3. t=t+1 6.2. for i=0 to n-1 in steps by 1 6.2.1. for j=i to n-1 in steps by 1 6.2.1.1. if p[i].arrival_time > p[j].arrival_time then 6.2.1.1.1. temp=p[j] 6.2.1.1.2. p[j]=p[i] 6.2.1.1.3. p[i]=temp 6.3. for i=0 to n-1 in steps by 1 6.3.1. if t>=p[i].arrival_time then 6.3.1.1. v=i 6.4. for i=0 to v in steps by 1 6.4.1. for j=i to v in steps by 1 6.4.1.1. if p[i].burst_time > p[j].burst_time then 6.4.1.1.1. temp=p[j] 6.4.1.1.2. p[j]=p[i] 6.4.1.1.3. p[i]=temp 6.5. for k=0 , i=0 to v in steps by 1 6.5.1. if p[i].burst_time > 0 then 6.5.1.1. k=k+1 6.5.2. if k=1 then 6.5.2.1. index=i 7. for i=0 to n-1 in steps by 1 7.1. for j=i to n-1 in steps by 1 7.1.1. if p[i].burst_time > p[j].burst_time then 7.1.1.1. temp = p[j] 7.1.1.2. p[j]=p[i] 7.1.1.3. p[i]= temp 8. for i=0 to n-1 in steps by 1

Page 10 of 16

Operating Systems Laboratory


8.1. if p[i].burst_time > = 0 then 8.1.1. order[pos]=p[i].name 8.1.2. t=t+p[i].burst_time 8.1.3. sum[pos+1]=t 9. for i=0 to pos-1 in steps by 1 9.1. write order[i] 10. for i=0to n-1 in steps by 1 10.1. for k=i to n-1 in steps by 1 10.1.1. if p[i]>arrival_time > p[k].arrival_time then 10.1.1.1. temp=p[i] 10.1.1.2. p[i]=p[k] 10.1.1.3. p[k]=temp 11. for i=0 to n-1 in steps by 1 11.1. for k=0 to pos-1 in steps by 2 11.1.1. if p[i].name = order[k] then 11.1.1.1. v=k 11.2. num1[i]=sum[v+i]-p[i].arrival_time 12. for i=0 to n-1 in steps by 1 12.1. num2[i]=num1[i]-num3[i] 13. for i= 0 to n-1 in steps by 1 13.1. tntime = tntime+num1[i] 13.2. wttime = wttime+num2[i] 14. Write Average waiting time = ,wttime/n 15. Write Average Turnaround time =,tntime/n 16. Stop Test Data: Input: Enter number of process: 4 Process 1: p1 Burst time: 5 Arrival time: 0 Process 2: p2 Burst time: 4 Arrival time: 1 Process 3: p3 Burst time: 2 Arrival time: 2 Process 4: p4 Burst time: 3 Arrival time: 3

Page 11 of 16

Operating Systems Laboratory

Title: Preemptive Priority

OS-O5

Aim: Write a program to implement preemptive priority CPU Scheduling algorithm Algorithm: 1. Start 2. Create a Class process with four properties name, arrival_time, burst_time, and priority as string, int, int, and int respectively 3. Read number of process, n 4. Create n process using array 5. for i=0 to n-1 in steps by 1 5.1. Create process p[i] 5.2. Read process name, p[i].name 5.3. Read process burst time, p[i].burst_time 5.4. Read process arrival time, p[i].arrival_time 5.5. Read process priority, p[i].priority 6. for pos=0 to t<p[n-1] in steps by 1 6.1. if p[index].burst_time > 0 then 6.1.1. order[pos]=p[index].name 6.1.2. p[index].burst_time=p[index].burst_time-1 6.1.3. t=t+1 6.2. for i=0 to n-1 in steps by 1 6.2.1. for j=i to n-1 in steps by 1 6.2.1.1. if p[i].arrival_time > p[j].arrival_time then 6.2.1.1.1. temp=p[j] 6.2.1.1.2. p[j]=p[i] 6.2.1.1.3. p[i]=temp 6.3. for i=0 to n-1 in steps by 1 6.3.1. if t>=p[i].arrival_time then 6.3.1.1. v=i 6.4. for i=0 to v in steps by 1 6.4.1. for j=i to v in steps by 1 6.4.1.1. if p[i].priority > p[j].priority then 6.4.1.1.1. temp=p[j] 6.4.1.1.2. p[j]=p[i] 6.4.1.1.3. p[i]=temp 6.5. for k=0 , i=0 to v in steps by 1 6.5.1. if p[i].burst_time > 0 then 6.5.1.1. k=k+1 6.5.2. if k=1 then 6.5.2.1. index=i 7. for i=0 to n-1 in steps by 1 7.1. for j=i to n-1 in steps by 1 7.1.1. if p[i].priority > p[j].priority then 7.1.1.1. temp = p[j] 7.1.1.2. p[j]=p[i] 7.1.1.3. p[i]= temp

Page 12 of 16

Operating Systems Laboratory


8. for i=0 to n-1 in steps by 1 8.1. if p[i].burst_time > = 0 then 8.1.1. order[pos]=p[i].name 8.1.2. t=t+p[i].burst_time 8.1.3. sum[pos+1]=t 9. for i=0 to pos-1 in steps by 1 9.1. write order[i] 10. for i=0to n-1 in steps by 1 10.1. for k=i to n-1 in steps by 1 10.1.1. if p[i]>arrival_time > p[k].arrival_time then 10.1.1.1. temp=p[i] 10.1.1.2. p[i]=p[k] 10.1.1.3. p[k]=temp 11. for i=0 to n-1 in steps by 1 11.1. for k=0 to pos-1 in steps by 2 11.1.1. if p[i].name = order[k] then 11.1.1.1. v=k 11.2. num1[i]=sum[v+i]-p[i].arrival_time 12. for i=0 to n-1 in steps by 1 12.1. num2[i]=num1[i]-num3[i] 13. for i= 0 to n-1 in steps by 1 13.1. tntime = tntime+num1[i] 13.2. wttime = wttime+num2[i] 14. Write Average waiting time = ,wttime/n 15. Write Average Turnaround time =,tntime/n 16. Stop Test Data: Input: Enter number of process: 3 Process 1: p1 Burst time: 4 Arrival time: 0 Priority: 2 Process 2: p2 Burst time: 3 Arrival time: 1 Priority: 3 Process 3: p3 Burst time: 3 Arrival time: 2 Priority: 1 Output: The order of process: p1 p3 p2 Average waiting time is 3.0

Page 13 of 16

Operating Systems Laboratory


Average turn around time 6.333

Page 14 of 16

Operating Systems Laboratory

Title: Preemptive Round Robin

OS-O5

Aim: Write a program to implement round robin preemptive CPU scheduling algorithm Algorithm: 1. Start 2. Create a Class process with four properties name, arrival_time, and burst_time as string, int, and int respectively 3. Read number of process, n 4. Create n process using array 5. for i=0 to n-1 in steps by 1 5.1. Create process p[i] 5.2. Read process name, p[i].name 5.3. Read process burst time, p[i].burst_time 5.4. Read process arrival time, p[i].arrival_time 5.5. tot = tot+p[i].burst_time 6. Read the time slice, ts 7. for i=0 to tot-1 in steps by 1 7.1. if p[index].burst_time >= ts then 7.1.1. order[j]=p[index].name 7.1.2. I=I+ts 7.1.3. p[index].burst_time = p[index].burst_time ts 7.1.4. sum[j+1]=I 7.2. else 7.2.1. order[j]=p[index].name 7.2.2. I=I+p[index].burst_time 7.2.3. p[index].burst_time = 0 7.2.4. sum[j+1]=I 7.3. for k=index to n-1 in steps by 1 7.3.1. if p[k].arrival_time <= I then 7.3.1.1. v=k 7.3.2. t=p[index] 7.3.3. for k= index to v-1 in steps by 1 7.3.3.1. p[k]=p[k+1] 7.3.4. p[v]=t 7.3.5. for k=index to n-1 in steps by 1 7.3.5.1. if p[index].burst_time > 0 then 7.3.5.1.1. break 7.3.5.2. else 7.3.5.2.1. index=index+1 8. for I=0 to j in steps of 1 8.1. Write order[I] 9. sort the process with respect to arrival time 10. for I=0 n-1 in steps by1 10.1. for k=0 to j-1 in steps by 1 10.1.1. if p[I].name = order[k] then 10.1.1.1. v=k

Page 15 of 16

Operating Systems Laboratory


10.2. num1[I]=sum[v+1]-p[I].arrival_time 11. for I=0 to n-1 in steps by 1 11.1. num2[I]=num1[I]-num3[I] 12. for I=0 to n-1 in steps by 1 12.1. tntime = tntime+num1[I] 12.2. wttime = wttime+num2[I] 13. Write Average Waiting time =, wttime/n 14. Write Average turnaround time = , attime/n 15. Stop Test Data Input: Enter number of process: 4 Process p1: p1 Burst time: 4 Arrival time: 0 Process p2: p2 Burst time: 3 Arrival time: 2 Process p3: p3 Burst time: 2 Arrival time: 3 Process p4: p4 Burst time: 7 Arrival time: 4 Time slice = 3 Output: Order: P1 p2 p3 p1 p4 Average waiting time = 3.75 Average turn around time = 8.0

Page 16 of 16

You might also like