0% found this document useful (0 votes)
23 views10 pages

Lab4 21522678

The document reports on the results of operating system lab 4, with sections completed on first come first served (FCFS) scheduling, shortest job first (SJF) scheduling, and round robin (RR) scheduling. Code is included to implement a round robin scheduling algorithm that calculates waiting times and turnaround times. Self-scores are listed but not completed for the different sections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Lab4 21522678

The document reports on the results of operating system lab 4, with sections completed on first come first served (FCFS) scheduling, shortest job first (SJF) scheduling, and round robin (RR) scheduling. Code is included to implement a round robin scheduling algorithm that calculates waiting times and turnaround times. Self-scores are listed but not completed for the different sections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Name: PHẠM TRUNG TÍN

ID:21522678
Class: IT007.N23.CNCL.1

OPERATING SYSTEM
LAB 4’S REPORT

SUMMARY
Task Status Page
Section 4.4(FCFS) Done 10
Section 4.5 SJF Done 12
RR Done 13

Self-scrores:

*Note: Export file to PDF and name the file by following format:
LAB X – <Student ID>.pdf
FCFS:
SJF:
RR:

#include <stdio.h>

#include <stdlib.h>
#define MAX 10

void drawGanttChart(int burst_time[], int n, int quantum)

int remaining_time[MAX];

int total = 0;

int remain = n;

int flag = 0;

int i;

printf("\nGantt Chart:\n\n");

for (int i = 0; i < n; ++i)

total += burst_time[i];

for (int i = 0; i < n; ++i)

remaining_time[i] = burst_time[i];

for (int process = 0; remain != 0; )

if (remaining_time[process] <= quantum && remaining_time[process])

printf("|P%d ", process + 1);

remaining_time[process] = 0;
flag = 1;

else if (remaining_time[process] > 0)

printf("|P%d ", process + 1);

remaining_time[process] -= quantum;

if (flag == 1)

--remain;

flag = 0;

if (process == n - 1)

process = 0;

else

++process;

printf("|");
flag = 0;

printf("\n");

for (i = 0; i <= total ; i += quantum)

printf("%d\t", i);

flag = 1;

if ((i % total) != 0)

printf("%d", total);

printf("\n\n");

void roundRobin(int burst_time[],int pn[], int n, int quantum)

int remaining_time[MAX];

int waiting_time = 0;

int turnaround_time = 0;

int flag = 0;

for (int i = 0; i < n; ++i)

remaining_time[i] = burst_time[i];

int process = 0;

int time = 0;
int remain = n;

printf("Process Name\t\tWaiting Time\tTurnaround Time\n");

while (remain != 0)

if (remaining_time[process] <= quantum && remaining_time[process] > 0)

time += remaining_time[process];

remaining_time[process] = 0;

flag = 1;

else if (remaining_time[process] > 0)

time += quantum;

remaining_time[process] -= quantum;

if (flag == 1)

--remain;

printf("\n%d\t%d\t%d\n", pn[process], time - burst_time[process], time);

waiting_time += time - burst_time[process];

turnaround_time += time;
flag = 0;

if (process == n - 1)

process = 0;

else

++process;

drawGanttChart(burst_time, n, quantum);

printf("Average turnaround time: %.2f\n", (float) turnaround_time / n);

printf("Average waiting time: %.2f", (float) waiting_time / n);

int main(void)

int n,pn[MAX], bt[MAX], quantum;

printf("number of processes (Max 10): ");

scanf("%d", &n);

for (int i = 0; i < n; ++i)


{

printf("\nprocess name,burst time:");

scanf("%d%d",&pn[i], &bt[i]);

printf("\nEnter the time quantum: ");

scanf("%d", &quantum);

printf("\n");

roundRobin(bt,pn, n, quantum);

printf("\n\n");

return 0;

You might also like