×
They know who you are. Show them what you can be.
--Your friends at LectureNotes
Close

Lab Manuals for Operating Systems - OS By Shivansh Singh

  • Operating Systems - OS
  • Practical
  • BABASAHEB BHIMRAO AMBEDKAR UNIVERSITY - BBAU
  • 101 Views
  • Uploaded 5 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

EXPERIMENT - 1 OBJECTIVE: Write a C Program to simulate the following Non-pre-emptive CPU scheduling algorithms to find Turnaround Time and Waiting Time for the above problem1. FCFS 2. SJF 3. ROUND ROBIN 4. PRIORITY DESCRIPTION: Assume all the processes arrive at the same time. FCFS CPU SCHEDULING ALGORITHM: For FCFS scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. The scheduling is performed on the basis of arrival time of the processes irrespective of their other parameters. Each process will be executed according to its arrival time. Calculate the waiting time and turnaround time of each of the processes accordingly. SJF CPU SCHEDULING ALGORITHM: For SJF scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. Arrange all the jobs in the order with respect to their burst times. There may be two jobs in queue with the same execution time, and then FCFS approach is to be performed. Each process will be executed according to the length of tits burst time. Then calculate the waiting time and turnaround time of each of the processes accordingly. ROUND ROBIN CPU SCHEDULING ALGORITHM: For ROUND ROBIN scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and the size of the time slice. Time slices are assigned to each process in equal portions and in circular order, handling all processes execution. This allows every process to get an equal chance. Calculate the waiting time and turnaround time of each of the processes accordingly. PRIORITY CPU SCHEDULING ALGORITHM: For PRIORITY scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and the priorities. Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue with the same priority, and then FCFS approach is to be performed. Each process will be executed according to its priority. Calculate the waiting time and turnaround time of each of the processes accordingly. 1

Text from page-2

PROGARM-1 //To implement FCFS CPU SCHEDULING ALGORITHM. PROGRAM: #include<stdio.h> main() { int bt[20], wt[20], tat[20], i, n; float wtavg, tatavg; printf("\nEnter the number of processes -- "); scanf("%d", &n); for(i=0; i<n; i++) { printf("\nEnter Burst Time for Process %d -- ", i); scanf("%d", &bt[i]); } wt[0]=wtavg=0; tat[0]=tatavg=bt[0]; for(i=1; i<n; i++) { wt[i]=wt[i-1]+bt[i-1]; tat[i]=tat[i-1]+bt[i]; wtavg=wtavg+wt[i]; tatavg=tatavg+tat[i]; } printf("\tPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND"); for(i=0; i<n; i++) printf("\n\tP%d\t\t%d\t\t%d\t\t%d", i, bt[i], wt[i], tat[i]); printf("\nAverage Waiting Time -- %f", wtavg/n); printf("\nAverage Turnaround Time -- %f", tatavg/n); } OUTPUT: 2

Text from page-3

PROGARM-2 //To implement SJF CPU SCHEDULING ALGORITHM. PROGRAM: #include<stdio.h> main() { int p[20], bt[20], wt[20], tat[20], i, k, n, temp; float wtavg, tatavg; printf("\nEnter the number of processes -- "); scanf("%d", &n); for(i=0; i<n; i++) { p[i]=i; printf("Enter Burst Time for Process %d -- ", i); scanf("%d", &bt[i]); } for(i=0; i<n; i++) for(k=i+1; k<n; k++) if(bt[i]>bt[k]) { temp=bt[i]; bt[i]=bt[k]; bt[k]=temp; temp=p[i]; p[i]=p[k]; p[k]=temp; } wt[0]=wtavg=0; tat[0]=tatavg=bt[0]; for(i=1; i<n; i++) { wt[i]=wt[i-1]+bt[i-1]; tat[i]=tat[i-1]+bt[i]; wtavg=wtavg+wt[i]; tatavg=tatavg+tat[i]; } printf("\n\tPROCESS\tBURST TIME\tWAITING TIME\tTURN AROUND TIME\n"); for(i=0; i<n; i++) printf("\n\tP%d\t\t%d\t\t%d\t\t%d", p[i], bt[i], wt[i], tat[i]); printf("\nAVERAGE WAITING TIME -- %f", wtavg/n); printf("\nAVERAGE TURNAROUND TIME -- %f", tatavg/n); } 3

Text from page-4

OUTPUT: 4

Lecture Notes