Lab4 21522678

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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