0% found this document useful (0 votes)
17 views9 pages

Operating System

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Operating System

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Practical File for “Operating System”

Submitted By Submitted To
NAME: DEV BHARDWAJ DR. DEVENDER KUMAR
Semester: 2
ASSOCIATE PROFESSSOR
Programme:
UNIVERSITY ROLL NO. Bachelor of Computer Applications

For June-2025 Examination

Department of Computer Science And Applications


FACULTY OF MANAGEMENT & COMMERCE
B A B A M A S T N AT H U N I V E R S I T Y
Asthal Bohar, Rohtak
List of programmes for Operating System Lab/Practical File:-
1. Write C program to simulate the FCFS CPU Scheduling algorithm.

2. Write C program to simulate the SJF CPU Scheduling algorithm.

3. Write C program to simulate the Round Robin CPU Scheduling algorithm.

4. Write a C program to simulate Bankers Algorithm for Deadlock Avoidance.

5. Write a C program to implement the Producer - Consumer problem using


semaphore

6. Write a C program to illustrate the IPC mechanism using Pipes.

7. Write a C program to illustrate the IPC mechanism using FIFOs.

8. Write a C program to simulate Paging memory management technique.

9. Write a C program to simulate Segmentation memory management technique.

10. Write a C program to simulate the Best Fit contiguous memory allocation
technique.

11. Write a C program to simulate the First Fit contiguous memory allocation
technique.

12. Write a C program to simulate the concept of Dining-Philosophers problem.


1. Write C program to simulate the FCFS CPU Scheduling algorithm:

Program code:

#include<stdio.h>
// Function to find the waiting time for all
// processes
void findWaitingTime(int processes[], int n,
int bt[], int wt[])
{
// waiting time for first process is 0
wt[0] = 0;

// calculating waiting time


for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}

// Function to calculate turn around time


void findTurnAroundTime( int processes[], int n,
int bt[], int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}

//Function to calculate average time


void findavgTime( int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;

//Function to find waiting time of all processes


findWaitingTime(processes, n, bt, wt);

//Function to find turn around time for all processes


findTurnAroundTime(processes, n, bt, wt, tat);

//Display processes along with all details


printf("Processes Burst time Waiting time Turn around time\n");

// Calculate total waiting time and total turn


// around time
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d ",(i+1));
printf(" %d ", bt[i] );
printf(" %d",wt[i] );
printf(" %d\n",tat[i] );
}
float s=(float)total_wt / (float)n;
float t=(float)total_tat / (float)n;
printf("Average waiting time = %f",s);
printf("\n");
printf("Average turn around time = %f ",t);
}

// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];

//Burst time of all processes


int burst_time[] = {10, 5, 8};

findavgTime(processes, n, burst_time);
return 0;
}

Output:

2. Write C program to simulate the SJF CPU Scheduling algorithm:


Program code:

#include <stdio.h>
int main()
{
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time.
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
// User Input Burst Time and alloting Process Id.
for (i = 0; i < n; i++) {
printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
// Sorting process according to their Burst Time.
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;

temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
// Calculation of Turn Around Time and printing the
// data.
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}

Output:

Enter number of process:


3. Write C program to simulate the Round Robin CPU Scheduling
algorithm:

Program code:

#include <stdio.h>

void main() {
int i, processes, sum = 0, cnt = 0, y, q, wt = 0, tat = 0, at[10], bt[10], temp[10];
float avg_waitt, avg_turnat;

// Input the number of processes


printf("Total number of processes in the system: ");
scanf("%d", &processes);

y = processes; // Assign number of processes to y

// Input arrival time and burst time for each process


for(i = 0; i < processes; i++) {
printf("\nEnter the Arrival and Burst time of Process[%d]\n", i + 1);
printf("Arrival time: ");
scanf("%d", &at[i]);
printf("Burst time: ");
scanf("%d", &bt[i]);
temp[i] = bt[i]; // Initialize remaining burst time
}

// Input the time quantum


printf("Enter the Time Quantum: ");
scanf("%d", &q);

// Display header for the process info


printf("\nProcess No \tBurst Time \tTAT \t\tWaiting Time\n");

// Scheduling loop
for(sum = 0, i = 0; y != 0;) {
if(temp[i] <= q && temp[i] > 0) {
sum = sum + temp[i];
temp[i] = 0;
cnt = 1;
} else if(temp[i] > 0) {
temp[i] = temp[i] - q;
sum = sum + q;
}

if(temp[i] == 0 && cnt == 1) {


y--; // Decrement remaining processes
printf("\nProcess No[%d] \t%d \t\t%d \t\t%d", i + 1, bt[i], sum - at[i], sum -
at[i] - bt[i]);
wt = wt + sum - at[i] - bt[i]; // Calculate waiting time
tat = tat + sum - at[i]; // Calculate turnaround time
cnt = 0;
}

if(i == processes - 1) {
i = 0;
} else if(at[i + 1] <= sum) {
i++;
} else {
i = 0;
}
}

// Calculate average waiting time and turnaround time


avg_waitt = wt * 1.0 / processes;
avg_turnat = tat * 1.0 / processes;

printf("\nAverage Turnaround Time: %f", avg_turnat);


printf("\nAverage Waiting Time: %f", avg_waitt);
}

Output:
//Input
Total number of processes in the system: 3

Enter the Arrival and Burst time of Process[1]


Arrival time: 0
Burst time: 5

Enter the Arrival and Burst time of Process[2]


Arrival time: 1
Burst time: 3

Enter the Arrival and Burst time of Process[3]


Arrival time: 2
Burst time: 4

Enter the Time Quantum: 3

//Output

Process No Burst Time TAT Waiting Time


Process No[1] 5 8 3
Process No[2] 3 6 3
Process No[3] 4 7 3

Average Turnaround Time: 7.000000


Average Waiting Time: 3.000000

You might also like