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

Green University of Bangladesh: Department of Computer Science and Engineering

The document contains code and explanations for sorting arrays, the FCFS scheduling algorithm, and FCFS scheduling with arrival times. It includes: 1) C code to sort an integer array in ascending order using a bubble sort algorithm. 2) An explanation of the FCFS scheduling algorithm and C code to calculate waiting times and turnaround times for a set of processes. 3) An extension of the FCFS code to also include arrival times for each process.
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)
45 views10 pages

Green University of Bangladesh: Department of Computer Science and Engineering

The document contains code and explanations for sorting arrays, the FCFS scheduling algorithm, and FCFS scheduling with arrival times. It includes: 1) C code to sort an integer array in ascending order using a bubble sort algorithm. 2) An explanation of the FCFS scheduling algorithm and C code to calculate waiting times and turnaround times for a set of processes. 3) An extension of the FCFS code to also include arrival times for each process.
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/ 10

Department of Computer Science and Engineering

Green University of
Bangladesh

Department of Computer Science and Engineering

Course Code: CSE-310

Course Title: Operating System Lab

Lab Report: 01

Submitted By: Submitted To:


Name: MD Shariful Islam MS. UMME HABIBA
ID: 181002182 Lecturer
Section: Day A Dept. of CSE
Dept.: CSE Green University of Bangladesh

Date of Submission: 24-10-2020


Sorting Array
Theory: Sorting is nothing but arranging the data in ascending or descending order. The term sorting
came into picture, as humans realized the importance of searching quickly. There are so many things in
our real life that we need to search for, like a particular record in database, roll numbers in merit list, a
particular telephone number in telephone directory, a particular page in a book etc. All this would have
been a mess if the data was kept unordered and unsorted, but fortunately the concept of sorting came
into existence, making it easier for everyone to arrange data in an order, hence making it easier to
search. Sorting arranges data in a sequence which makes searching easier.

Code
#include <stdio.h>

int main()
{
int array[100], n, c, d, swap;

printf("Enter number of elements\n");


scanf("%d", &n);

printf("Enter the %d element\n", n);

for (c = 0; c < n; c++)


scanf("%d", &array[c]);

for (c = 0 ; c < n - 1; c++)


{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d]>array[d+1])
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf(" Sorted array in ascending order :\n");

for(c=0; c < n; c++)


printf("%d\n", array[c]);

return 0;
}
Output
FCFS Algorithm
Theory: FCFS stands for First Come First Serve. In the FCFS scheduling algorithm, the job that arrived
first in the ready queue is allocated to the CPU and then the job that came second and so on. We can say
that the ready queue acts as a FIFO (First In First Out) queue thus the arriving jobs/processes are placed
at the end of the queue. FCFS is a non-preemptive scheduling algorithm as a process holds the CPU until
it either terminates or performs I/O. Thus, if a longer job has been assigned to the CPU then many
shorter jobs after it will have to wait. This algorithm is used in most of the batch operating systems.

Code

#include <stdio.h>

int main()

int pid[10],bustime[20],t_time[20],w_time[20],n, i, j, total_w,total_tat, swap ;

float avg_wt, avg_tt;

printf("Enter number of array list \n");

scanf("%d", &n);

printf( "enter Array list ");

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

scanf( "%d",&bustime[i]);
}

w_time[0]=0;

avg_wt=0;

avg_tt=t_time[0]=bustime[0];

for(i=1 ; i<n ;i++)

{w_time[i]=w_time[i-1]+bustime[i-1];

t_time[i]=w_time[i]+ bustime[i];

avg_wt+=w_time[i];

avg_tt+=t_time[i];

avg_wt =avg_wt/n;

avg_tt =avg_tt/n;

printf( "process\t burst time\t waiting time\t turnaround time\n");

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

printf( "\n p%d \t\t %d\t\t %d\t\t %d\n" ,i, bustime[i] ,w_time[i], t_time[i]);

}
printf("avarage wating time %f\n",avg_wt );

printf("avarage turnaround time %f\n",avg_tt );

return 0;

Output

FCFS Arrival Time

Theory: First come first serve (FCFS) scheduling algorithm simply schedules the jobs
according to their arrival time. The job which comes first in the ready queue will get the CPU
first. The lesser the arrival time of the job, the sooner will the job get the CPU.

Code
#include <stdio.h>

int main()

int pid[10],bustime[20],t_time[20],w_time[20] ,arr_t[20] ,n, i, j, total_w,total_tat, swap ;

float avg_wt, avg_tt;

printf("Enter number of array list \n");

scanf("%d", &n);

printf( "enter Array list \n");

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

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

printf("enter the arrival time \n");

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

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

}
w_time[0]=0;

avg_wt=0;

avg_tt=t_time[0]=bustime[0];

for(i=1 ; i<n ;i++)

{w_time[i]=w_time[i-1]+bustime[i-1];

t_time[i]=w_time[i]+ bustime[i];

avg_wt+=w_time[i];

avg_tt+=t_time[i];

avg_wt =avg_wt/n;

avg_tt =avg_tt/n;

printf( "process\t burst time \t arrival time \t waiting time\t turnaround time\n");

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

printf( "\n p%d\t %d\t\t %d \t\t %d\t\t %d\n " ,i, bustime[i] ,arr_t[i] ,w_time[i], t_time[i]);

printf("avarage wating time %f\n",avg_wt );


printf("avarage turnaround time %f\n",avg_tt );

return 0;

Output

You might also like