Lab Doc Manual
Lab Doc Manual
Aim:
Procedure:
Installing Window:
1.Obtain the installation media (e.g. a Windows installation USB drive or DVD).
2. Connect the installation media to your computer and restart the machine.
3. Boot the machine from the installation media by changing the boot order in the
BIOS or UEFI settings.
4. Follow the on-screen instructions to install Windows. You will need to accept
the license agreement, select the installation type (e.g. custom or upgrade), choose
the installation location (e.g. which hard drive and partition), and configure basic
settings such as language, time and currency format, and keyboard input method.
5. Once the installation is complete, the machine will restart and guide you through
the initial setup process.
Installing Linux:
2. i ,UNIX COMMANDS
Aim:
To execute the basic Unix commands
Commands
1. date command
The date command is used to display the current date with day of weak,
month, day, time and the year.
Syntax : date
The date command can also be used with the following format specification.
Format Purpose
Date +%m It displays the month number
Date +%h It displays the month name
Date +%d It displays the day of month
Date +%y It displays the last two digits of the year
Date +%H It displays the hour
Date +%M It displays the minutes
Date +%S It displays the seconds
2. who command
It is used to display the data about all the users, who are currently logged in to the
system. It displays the output format as login date with time.
Syntax : who
3. who am i
It displays the username, terminal line, login date and time.
Syntax : who am i
4. cal command
It is used to displays the calander.
Syntax : cal month and year
5.clear command
It is used to clear the screen
Syntax : clear
6. echo command
It is used to print the message on the screen whatever you have typed on the screen
Syntax : echo text
7.id command
It is used to displays the numerical value that corresponds to your login name.
Syntax : id
8.bc command
unix offer an online calculator and can be invoked by the command bc.
Syntax :bc
9. cat command
It is used to create a file
Syntax : cat >file name
Ex: cat >abc
Raja
Ragu
Cat file name
It is used to displays the contents of the file.
Syntax : cat filename
10. ctrl+z
It is used to save the file
11.cp command
It is used to copy the content of one file to another file.
Syntax : cp source filename destination filename
12.rm command
It is used to delete the file
Syntax :rm file name
13.mv command
It is used to rename a file
Syntax : mv filename new filename
14.word count
It is used to count and displays the number of words or sentences or characters
Syntax :wc file name
Ex :wc –l file name
It displays the number of lines
wc –w file name
It displays the number of words
wc –c file name
It displays the number of characters
15. ls command
It is used to lists all the files in current directory.
Syntax :ls
Ex: ls –a
It displays the all the files including hidden files in the current directory
ls –i
It displays all the files with I as node number
ls –t
it list the files sorted by last modified time
ls –tt
it list the files sorted by last access time
ls –lt
it list files in long form sorted by last modified time
Ls -r
ls ?
ls ??
ls *
16 .diff command
17.rmdir command
rm -r
18.mk directory
19.cd command
it is used to change the current directory
syntax : cd directory name
cd.
cd..
20.mv command
2. ii SHELL PROGRAM
Aim :
To implement the following program Employee Payroll, Simple Function, Greatest among three
numbers, Factorial of given number using shell program.
Employee Payroll:
Algorithm :
get()
{
echo “Enter id, allowance, deduction, basic pay”
read id
read all
readded
read basic
}
display()
{
echo “the id is $id”
echo “the allowance is $all”
echo “the deduction is $ded”
echo “the Basic pay is $basic”
}
get $id,$all,$ded,$basic
display
gross=$(($basic + $all))
net=$((gross - $ded))
echo “the gross is $gross
echo “the net is $net”
Simple function using shell:
Algorithm :
Aim
fork()
The fork system call is used to create a new process called child process.
Both the child and parent continue to execute the instructions following fork call.
The getppid system call returns parent process ID of the calling process
Algorithm
Print value of x
5. Otherwise
Print value of x
6. Stop
Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
main()
pid_tpid;
int x = 5;
pid = fork();
x++;
if (pid< 0)
exit(-1);
else if (pid == 0)
printf("Child process:");
else
printf("\nParent process:");
}
Result
Thus a child process is created with copy of its parent's address space.
Aim
execl()
The exec family of function (execl, execv, execle, execve, execlp, execvp) is used
by thechild process to load a program and execute.
execl system call requires path, program name and null pointer
Algorithm
a. Suspend parent process until child completes using wait system call
6. Stop
Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
main()
pid_tpid;
switch(pid = fork())
case -1:
perror("Fork failed");
exit(-1);
case 0:
printf("Child process\n");
exit(0);
default:
wait(NULL);
printf("Child Terminated\n");
exit(0);
Result
Thus the child process loads a binary executable file into its address space.
Aim
To block a parent process until child completes using wait system call.
wait()
The wait system call causes the parent process to be blocked until a child
terminates.
When a process terminates, the kernel notifies the parent by sending the
SIGCHLD signal to the parent.
Without wait, the parent may finish first leaving a zombie child, to be adopted by
init process
Algorithm
a. Suspend parent process until child completes using wait system call
6. Stop
Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
main()
inti, status;
pid_tpid;
pid = fork();
if (pid< 0)
exit(-1);
}
else if(pid> 0)
wait(NULL);
for (i=2;i<=10;i+=2)
printf ("%3d",i);
else if (pid == 0)
for (i=1;i<10;i+=2)
printf ("%3d",i);
Result
Thus using wait system call zombie child processes were avoided.
Exno: 4Write C programs to implement the various CPU Scheduling
Algorithms a.FCFS SCHEDULING ALGORITHM
Aim:
To write a program to implement First Come First Serve scheduling algorithm using C program
Algorithm :
Output :
Enter the number of processes : 3
Enter the processes and burst time :
1 10
2 4
3 6
Gantt Chart
P1 P2 P3
0 10 14 20
Process Waiting time
P1 0
P2 10
P3 14
Average waiting time of processes is 8.0000
Process turn around time
P1 10
P2 14
P3 20
Average turn around time of processes is 14.666667
Result :
Thus the program FCFS scheduling algorithm is implemented.
Output :
Enter the number of processes : 3
Enter the processes and burst time :
1 10
2 6
3 12
Gantt Chart
P2 P1 P3
0 6 16 28
Process Waiting time
P2 0
P1 6
P3 16
Average waiting time of processes is 7.3333
Process turn around time
P2 6
P1 16
P3 28
Average turn around time of processes is 16.666667
Result :
Thus the program FCFS scheduling algorithm is implemented.
4.C PRIORITY SCHEDULING ALGORITHM
Aim:
To write a program to implement priority scheduling algorithm using C program
Algorithm :
Output :
Enter the number of processes : 3
Enter the process, Burst time& priority of processes
1 10 3
2 5 1
3 3 2
Gantt Chart
P2 P3 P1
0 5 8 18
Process Waiting time
P2 0
P3 5
P1 8
Average waiting time of processes is 4.3333
Process turn around time
P2 5
P3 8
P1 18
Average turn around time of processes is 10.33333
Result :
Thus the program priority scheduling algorithm is implemented.
4.d ROUND ROBIN SCHEDULING ALGORITHM
Aim:
To write a program to implement Round Robin scheduling algorithm using C program
Algorithm :
Output :
Enter the number of processes : 3
Enter the processes
1
2
3
Enter the burst time
6
5
4
Enter the time quantum : 2
Gantt Chart
P1 P2 P3 P1 P2 P3 P1 P2
0 2 4 6 8 10 12 14 15
Process Waiting time
P1 8
P2 10
P3 8
Average waiting time of processes is 8.66667
Process turn around time
P1 14
P2 15
P3 12
Average turn around time of processes is 13.66667
Result :
Thus the program Round Robin scheduling algorithm is implemented.
Aim:
To Illustrate the inter process communication strategy
Algorithm:
Step 1: Start the program.
Step 2: Create a pipe using the pipe() system call and store the read and write ends of the pipe in
fd[0] and
fd[1], respectively.
Step 3: Fork the current process using the fork() system call and store the return value in pid.
Step 4: If pid is negative, an error occurred during forking, so print an error message and exit the
program.
Step 5: If pid is greater than zero, this is the parent process.
Step 6: Generate a random number using the rand() function and print it to the console.
Step 7: Write the number to the write end of the pipe using the write() system call.
Step 8: Close the write end of the pipe using the close() system call.
Step 9: If pid is zero, this is the child process.
Step 10: Read the number from the read end of the pipe using the read() system call.
Step 11: Multiply the number by 2.
Step 12: Write the result to the write end of the pipe using the write() system call.
Step 13: Close the read end of the pipe using the close() system call.
Step 14: Exit the child process using the exit() system call.
Step 15: Back in the parent process, wait for the child process to complete using the wait()
system call.
Step 16: Read the result from the read end of the pipe using the read() system call.
Step 17: Print the result to the console.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
int fd[2];
pid_t pid;
if (pipe(fd) == -1) {
perror("pipe");
exit(1);
}
pid = fork();
if (pid < 0) {
perror("fork");
exit(1);
}
if (pid > 0) {
// Parent process
int number;
close(fd[0]); // Close read end of the pipe
number = rand() % 100; // Generate a random number
printf("Parent process generated number: %d\n", number);
write(fd[1], &number, sizeof(number)); // Write number to the pipe
close(fd[1]); // Close write end of the pipe
}
else {
// Child process
int number, result;
close(fd[1]); // Close write end of the pipe
read(fd[0], &number, sizeof(number)); // Read number from the pipe
printf("Child process received number: %d\n", number);
result = number * 2; // Multiply the number by 2
write(fd[1], &result, sizeof(result)); // Write the result to the pipe
close(fd[0]); // Close read end of the pipe
}
return 0;
}
Output:
Result:
EXNO:6 Implement mutual exclusion by Semaphores
Aim:
To write a program to implement semaphore using C program
Algorithm :
Result :
Thus the program semaphore is implemented.
Aim:
To write a program to implement Bankers algorithm using C program
Algorithm :
Aim:
To Write a C program to Implement Deadlock Detection Algorithm
Algorithm :
1. Let Work and Finish be vectors of length m and n respectively. Initialize Work=
Available. For i=0, 1, …., n-1, if Requesti = 0, then Finish[i] = true; otherwise, Finish[i]=
false.
Program:
#include<stdio.h>
static int mark[20];
int i, j, np, nr;
int main()
{
int alloc[10][10],request[10][10],avail[10],r[10],w[10];
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&request[i][j]);
}
}
//marking processes with zero allocation
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
{
if(alloc[i][j]==0)
count++;
else
break;
}
if(count==nr)
mark[i]=1;
}
// initialize W with avail
for(j=0;j<nr; j++)
w[j]=avail[j];
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
}
}
}
if(deadlock)
printf("\n Deadlock detected");
else
printf("\n No Deadlock possible");
}
OUTPUT:
209
110
136
951
Deadlock Detected
Result:
Aim:
Algorithm:
Step 1: Define a function func that takes a void* argument and returns a void* pointer.
Step 2: Inside the func function, detach the current thread using pthread_detach(pthread_self())
so that it can continue running independently of the parent thread.
Step 3: Print a message indicating that the function is running.
Step 4: Exit the thread using pthread_exit(NULL) so that it terminates.
Step 5: Define a function fun.
Step 6: Declare a pthread_t variable named ptid to store the ID of the new thread that will be
created.
Step 7: Inside the fun function, create a new thread using pthread_create(&ptid, NULL, &func,
NULL) with the func function as the thread function.
Step 8: Print a message indicating that the current line may be printed before the thread
terminates.
Step 9: Compare the ID of the current thread with the ID of the newly created thread using
pthread_equal(ptid, pthread_self()).
Step 10: If the IDs are equal, print a message indicating that the threads are equal.
Step 11: If the IDs are not equal, print a message indicating that the threads are not equal.
Step 12: Wait for the newly created thread to terminate using pthread_join(ptid, NULL).
Step 13: Print a message indicating that the current line will be printed after the thread ends.
Step 14: Exit the thread using pthread_exit(NULL).
Program:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* func(void* arg)
{
// detach the current thread
// from the calling thread
pthread_detach(pthread_self());
printf("Inside the thread\n");
// exit the current thread
pthread_exit(NULL);
}
void fun()
{
pthread_t ptid;
// Creating a new thread
pthread_create(&ptid, NULL, &func, NULL);
printf("This line may be printed"
" before thread terminates\n");
// The following line terminates
// the thread manually
// pthread_cancel(ptid);
// Compare the two threads created
if(pthread_equal(ptid, pthread_self())
printf("Threads are equal\n");
else
printf("Threads are not equal\n");
// Waiting for the created thread to terminate
pthread_join(ptid, NULL);
printf("This line will be printed"
" after thread ends\n");
pthread_exit(NULL);
}
int main()
{
fun();
return 0;
}
OUTPUT:
Result:
EXNO: 10 Implement the paging Technique using C program
Aim:
To write a program to implement paging using C program
Algorithm :
Result :
Thus the program Paging is implemented.
EXNO: 11 Write C programs to implement the following Memory Allocation
Methods a. First Fit
Aim:
Algorithm:
Step 1: Initialize the memory and memory status arrays to indicate that all
memory blocks are free.
Step 2: Search for the first contiguous block of free memory that is large enough to
hold the requested size.
Step 3: If a block of sufficient size is found, allocate the block by setting the status
of each memory location in the block to "allocated" and return a pointer to the
beginning of the block.
Step 4: If a block of sufficient size is not found, return NULL to indicate that the
allocation failed.
Program:
#include <stdio.h>
#define FREE 0
#define ALLOCATED 1
int memory[MAX_MEMORY];
int memoryStatus[MAX_MEMORY];
void initMemory() {
memory[i] = 0;
memoryStatus[i] = FREE;
}
void displayMemory() {
printf("Memory:\n");
if(memoryStatus[i] == ALLOCATED) {
else {
printf("- ");
printf("\n");
int count = 0;
if(memoryStatus[i] == FREE) {
if(count == 0) {
startIndex = i;
count++;
}
else {
memoryStatus[j] = ALLOCATED;
return &memory[startIndex];
count = 0;
memoryStatus[j] = ALLOCATED;
return &memory[startIndex];
return NULL;
int main() {
initMemory();
displayMemory();
if(p1 != NULL) {
*p1 = 10;
}
if(p2 != NULL) {
*p2 = 20;
displayMemory();
return 0;
OUTPUT
RESULT
ALGORITHM:
Step 3: Get the number of blocks,files,size of the blocks using for loop.
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
ff[i]=j;
break;
frag[i]=temp;
bf[ff[i]]=1;
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
OUTPUT:
Result:
ALGORITHM:
Step 3: Get the number of blocks,files,size of the blocks using for loop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
ff[i]=j;
lowest=temp;
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step 1: Start the process
Step 2: Declare page number, page table, frame number and process size.
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;
pthread_mutex_lock(&lock);
unsigned long i = 0;
counter += 1;
for(i=0; i<(0xFFFFFFFF);i++);
return NULL;
int main(void)
int i = 0;
int err;
if (pthread_mutex_init(&lock, NULL) != 0)
return 1;
while(i < 2)
if (err != 0)
i++;
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;}
OUTPUT:
Result:
EXNO: 13 Write C programs to Implement the various File Organization
Techniques a. Single Level Directory
Aim:
ALGORITHM:
Step-6: Using the file eclipse function define the files in a single level
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void main()
int gd=DETECT,gm,count,i,j,mid,cir_x;
char fname[10][20];
clrscr();
initgraph(&gd,&gm,"c:/tc/bgi");
cleardevice();
setbkcolor(GREEN);
scanf("&d",&count);
if(i<count)
cleardevice();
setbkcolor(GREEN);
scanf("%s",fname[i]);
setfillstyle(1,MAGENTA);
mid=640/count;
cir_x=mid/3;
bar3d(270,100,370,150,0,0);
settextstyle(2,0,4);
settextjustify(1,1);
outtextxy(320,125,"root directory");
setcolor(BLUE);
i++;
for(j=0;j<=i;j++,cir_x+=mid)
line(320,150,cir_x,250);
fillellipse(cir_x,250,30,30);
outtextxy(cir_x,250,fname[i]);
}}
getch();
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step-6: Using the file eclipse function define the files in a single level
PROGRAM:
#include<stdio.h>
#include<graphics.h>
struct tree_element
char name[20];
int x,y,ftype,lx,rx,nc,level;
};
void main()
{int gd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"null",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\tc\bgi");
display(root);
getch();
closegraph();
{int i, gap;
if(*root==NULL)
{(*root)=(node*)malloc(sizeof(node));
fflush(stdin);
gets((*root)->name);
if(lev==0 || lev==1)
(*root)-> ftype=1;
else
(*root)->ftype=2;
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx ;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{if(lev==0 || lev==1)
{if((*root)->level==0)
else
printf("(for %s):",(*root)->name);
scanf("%d",&(*root)->nc);
}else
(*root)->nc=0;
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i]),lev+1,(*root)-
>name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}else
(*root)->nc=0;
}}
display(node *root)
{int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root!=NULL)
{for(i=0;i<root->nc;i++)
{line(root->x,root->y,root->link[i]->x,root->link[i]->y);
}if(root->ftype==1)
bar3d(root->x-20, root->y-10,root->x+20,root->y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
{display(root->link[i]);
}}}
OUTPUT
RESULT
AIM:
To write a C program for sequential file for processing the student information.
ALGORITHM:
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-5: Using do..While statement and switch case to create the options such as 1-
DISPLAY, 2.SEARCH, 3.EXIT.
PROGRAM:
#include<stdio.h>
#include<conio.h>
typedef struct
{int sno;
}STD;
void main()
{int i,n,sno_key,opn;
FILE *fp;
clrscr();
scanf(“%d”,&n);
fp=fopen(“stud.dat”,”w”);
for(i=0;i<n;i++)
scanf(“%d%s%d%d%d,&s.sno,s.name,&s.m1,&s.m2,&s.m3);
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
fp=fopen(“stdu.dat”,”r”);
do
scanf(“%d”,&open);
switch(opn)
case 1:
display(fp);
break;
case 2:
scanf(“%d”,&sno_key);
if(search(fp,sno_key)){
printf(“%d\t%s\t%d\t%d\t%d\n”, s.sno,s.name,s.m1,s.m2,s.m3);
else
break;
case 3:
getch();
break;
default:
break;
}
}while(opn!=3);
fclose(fp);
{rewind(fp);
while(fread(&s,sizeof(s),1,fp))
printf(“%d\t%s\t%d\t%d\t%d\n”,s.sno,s.name,s.m1,s.m2,s.m3);
{rewind(fp);
while(fread(&s,sizeof(s),1,fp))
If(s.sno==sno_key)
return 1;
return 0;
OUTPUT:
Result:
AIM:
To write a C program for random access file for processing the employee details.
ALGORITHM:
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-4: Store the entered information in the system.
Step-5: Using do..While statement and switch case to create the options such as
PROGRAM:
#include<stdio.h>
#include<conio.h>
int f[50],i,k,j,inde[50],n,c,count=0,p;
main()
clrscr();
for(i=0;i<50;i++)
f[i]=0;
x:
scanf("%d",&p);
if(f[p]==0)
f[p]=1;
scanf("%d",&n);
}
else
goto x;
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
goto x;
for(j=0;j<n;j++)
f[inde[j]]=1;
printf("\n allocated");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
scanf("%d",&c);
if(c==1)
goto x;
else
exit();
getch();
AIM:
To write a C program for random access file for processing the employee details.
ALGORITHM:
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-5: Using do..While statement and switch case to create the options such as
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct record
char empname[20];
int age;
float salary;
};
FILE *people;
void main()
person employee;
int I,n;
FILE *fp;
scanf(“%d”,&n);
fp=fopen(“PEOPLE.txt”,”w”);
for(i=0;i<n;i++)
scanf(“%s%d%f”,employee.empname,&employee.age,& employee.salary);
fwrite(,&employee.sizeof(employee,1,people);
fclose(fp);
int rec,result;
people=fopen(“PEOPLE.txt”,”r”);
scanf(“%d”,&rec);
while(rec>=0)
{
fseek(people,rec*sizeof(employee),SEEK_SET);
result=fread(&em[ployee,sizeof(employee),1,people)
if(result==1)
printf(“Age:%d years\n”,employee.age);
else
scanf(“%d”<&rec):
fclose(people):
getch():
OUTPUT:
RESULT:
EXNO:15 Write C programs for the implementation of various disk
scheduling algorithms
Aim:
Write C programs for the implementation of various disk scheduling algorithms
Algorithm:
Program
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int queue[20], n, head, i;
float avg_seek_time;
printf("Enter the number of requests: ");
scanf("%d", &n);
printf("Enter the queue of disk positions to be read: ");
for (i = 0; i < n; i++) {
scanf("%d", &queue[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &head);
int distance = abs(head - queue[0]);
for (i = 1; i < n; i++) {
distance += abs(queue[i] - queue[i-1]);
}
avg_seek_time = (float)distance / n;
printf("Average seek time = %f\n", avg_seek_time);
return 0;
}
OUTPUT:
RESULT: