×
Stop thinking about WHAT WILL HAPPEN and start thinking about WHAT YOU CAN DO.

# Lab Manuals for Operating Systems - OS By Shivansh Singh

• Operating Systems - OS
• Practical
• BABASAHEB BHIMRAO AMBEDKAR UNIVERSITY - BBAU
• 110 Views
Page-1

#### Lab Manuals for Operating Systems - OS By Shivansh Singh

Experiment: / 15

0 User(s)

#### 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, wt, tat, 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=wtavg=0; tat=tatavg=bt; 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, bt, wt, tat, 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=wtavg=0; tat=tatavg=bt; 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

OUTPUT: 4