0% found this document useful (0 votes)
19 views76 pages

Os Lab Manul-1

The document is a laboratory manual for an Operating Systems Lab course in the Computer Engineering department, outlining the institute's vision and mission, as well as the department's objectives. It details program outcomes, educational objectives, specific outcomes, and lab outcomes, including various experiments related to Linux commands, process management, memory management, and file management. The manual aims to provide students with practical skills and knowledge necessary for their future careers in engineering.
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)
19 views76 pages

Os Lab Manul-1

The document is a laboratory manual for an Operating Systems Lab course in the Computer Engineering department, outlining the institute's vision and mission, as well as the department's objectives. It details program outcomes, educational objectives, specific outcomes, and lab outcomes, including various experiments related to Linux commands, process management, memory management, and file management. The manual aims to provide students with practical skills and knowledge necessary for their future careers in engineering.
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/ 76

DEPARTMENT OF COMPUTER ENGINEERING

CLASS:SE SEMESTER:IV

LABORATORY MANUAL

OPERATING SYSTEM LAB

(CSL403)
INSTITUTE VISION

To be come an institute of excellence by continuous implementation and updation of knowledge and


upgradation of technical skills to serve the society and improve the quality of life.

INSTITUTE MISSION

M1-To teach students basic concepts of science and fundamental engineering principles by encouraging inter
disciplinary approach for comprehensive broad-based learning.
M2-To provide hands-on training by executing project-based learning, industrial internships and value-added
programs.
M3-To train professional thinking and attitude building to be sensitive to needs of the society.

DEPARTMENTVISION

To become a meritorious branch of Computer Engineering for imparting high quality education and technical
skills necessary for industrial needs and society

DEPARTMENTMISSION

M1-To enhance career opportunities through project based learning and value added programs.
M2-To develop graduates for competitive examinations and inculcate entrepreneurial skills to acquire higher
goals of excellence.
M3-To include professional behavior, ethical values and inter disciplinary research capabilities.
Program Outcomes

Sr.No PO Code Program Outcomes Statements

Engineering knowledge: Apply the knowledge of mathematics, science, engineering


1 PO.1 fundamentals, and an engineering specialization to the solution of complex engineering
problems.
Problem Analysis: Identify, formulate, review research literature, and analyze
2 PO.2 complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
Design / development of solutions: Design solutions for complex engineering
3 PO.3 problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and
4 PO.4 research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and
5 PO.5 modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the modern computer
6 PO.6 technology to assess societal & education, healthcare, banking & insurance, safety,
legalandculturalissuesandtheconsequentresponsibilitiesrelevanttothe
Professional informational technology engineering practice.
Environmentandsustainability:Understandtheimpactoftheprofessional
7 PO.7 Computer engineering solution sin societal and environmental contexts,and demonstrate
the knowledge of, and need for sustainable development.
8 PO.8 Ethics: Apply ethical principles and commit to professional and computer ethics and
responsibilities and norms of the engineering practice.
9 PO.9 Individual and team work: Function effectively as an individual technologist, and as a
member or leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex software and computer
10 PO.10 automation activities with the engineering community and with society at large, such
as, being able to comprehend and write effective reports and design documentation,
make effective presentations, and give and receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of the
11 PO.11 software too lsand management principles and apply the setoone’s own work,as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
Life-long learning: Recognize the need for, and have the preparation and ability to
12 PO.12 engage in independent and life-long learning in the broadest context of technological
change.
Program Educational Outcomes

PEO
Program Educational Objectives Statements
Code

To prepare the Learner with a sound foundation in the mathematical, scientific and
PEO.1
Engineering fundamentals.

To motivate the Learner in the art of self-learning and to use modern tools for
PEO.2
solving real life problems.

To equip the Learner with broad education necessary to understand the impact of
PEO.3
Computer Science and Engineering in a global and social context.

PEO.4 To encourage, motivate and prepare the Learner‘s for Lifelong-learning.

To inculcate professional and ethical attitude, good leadership qualities and


PEO.5 commitment to social responsibilities in the Learners' thought process.
Program Specific Objectives

Sr.No PSOCode Program Specific Outcomes Statements

PSO1: Mathematical Concepts: Equipped with the knowledge to infer


the Computational mathematical models for problem solving using data
1 PSO.1
structures, discrete structures, computer architecture and design and
analysis of algorithms.

PSO2:Software Development: Demonstrate the ability to analyze,


design, and develop applications in a variety of fields utilizing
2 PSO.2
computational models and simulations to give solutions based on novel
concepts.
PSO3:Transferring Skills: Demonstrate the ability to provide solutions
3 PSO.3 for real world problems through acquaintance and project
implementation and hands-on training.
Lab Outcomes

LO Code Lab Outcomes Statements


Demonstrate basic Operating system Commands, Shell scripts, System Calls and
LO.1
API wrt Linux

LO.2 Implement various process scheduling algorithms and evaluate their performance.

LO.3 Implement and analyze concepts of synchronization and deadlocks.


Implement various Memory Management techniques and evaluate their
LO.4
performance.
LO.5 Implement and analyze concepts of virtual memory.
Demonstrate and analyze concepts offile management and I/O management
LO.6
techniques.
PROFILE

Name of Student:
ARMIETPIN:
Roll No.
Exam Seat No.

INDEX
Sr.No. Name of Experiment

Explore Linux Commands:

1.1 Explore usage of basic Linux Commands and system calls for file,
directory and process management.
1
For eg (mkdir, chdir, cat, ls, chown. chmod, chgp,ps etc.
systemcalls:open,read,write,close,getpid,setpid, getuid, getgid, getegid.geteuid,
sort, grep, awk, etc.) [LO1]

Linux shell script

2.1 Write shell scripts to do the following:

a. Display OS version, release number, kernel version

2 b. Display top10 processes in descending order


c. Display processes with high est memory usage.

d. Display current logged in user and log name.

e. Display current shell, home directory, operating system type, current path
setting, current working directory.[L01]

Linux- API
3.1 Implement anyone basic commands of Linux like is, cp, my and others using
3
kernel APIs.[LO1]
Linux-Process
a. Create a child process in Linux using the fork system call. From the child
process obtain the process ID of both child and parent by using get pid and get
4 pid system call.

b. Explore wait and wait pid before termination of process.[LO2]

Process Management: Scheduling


5
a. Write a program to demonstrate the concept of non- preemptive scheduling
algorithms.
b. Write a program to demonstrate the concept of
Preemptive scheduling algorithms.[LO2]
Process Management: Synchronization
a. Write a C program to implement solution of Producer consumer problem
6
through Semaphore[LO3]
Process Management: Deadlock

a. Write a program to demonstrate the concept of deadlock avoidance through


Banker's Algorithm.
7
b. Write a program demonstrates the concept of Dining Philospher's
Problem.[LO3]
Memory Management
a. Write a program to demonstrate the concept of MVT and MFT memory
management techniques
8 b. Write a program to demonstrate the concept of dynamic partitioning
placement algorithms i.e. BestFit, FirstFit,
Worst-Fit etc.[LO4]
Memory Management: Virtual Memory

a. Write a program to demonstrate the concept of demand paging for


9
simulation of Virtual Memory implementation.
b. Write a program in C demonstrate the concept of page
Replacement policies for handling page faults eg:FIFO,
LRUetc.[LO5]
File Management & I/O Management
a. Write a C program to simulate File allocation strategies typically sequential,
indexed and linked files

b. Write a C program to simulate file organization of multi- level directory


10
structure.

c. Write a program in C to do disk scheduling-FCFS, SCAN, C-SCAN[L06]


EXPERIMENTNO: 1

AIM: To study the basic commands in Linux.


COMMANDS:

1. Task: To display system date and time.


Syntax: Date
Explanation: This command displays the current date and time on the screen.

2. Task: To display current


month. Syntax: Date+%mc
Explanation: This command displays the current month on the screen.

3. Task: To display the name of the current


month. Syntax: Date+%h
Explanation: This command displays name of the current month on the screen.

4. Task: To display current system date.


Syntax: Date+%d
Explanation: This command displays the current system date on the screen.

5. Task: To display current year. Syntax: Date+%y


Explanation: This command displays the current year on the screen.

1
6. Task: To display current system time.
Syntax: Date+%H
Explanation: This command displays the current system time on the screen.

7. Task: To display current system time in minutes


.Syntax: Date+%m
Explanation: This command displays the current system time in minutes on the screen.

8. Task: To display current system time in seconds.


Syntax: Date+%s
Explanation: This command displays the current system time in seconds on the screen.

9. Task: To display the calendar of current month.


Syntax: cal
Explanation: This command displays the current month calendar on the screen.

10. Task: To display user defined message.


Syntax: ‘echo‘message’
Explanation: This command displays the message.

Conclusion: In this experiment we have run all the basic linux commands. Through this experiment, you
have become familiar with basic unix commands. These commands are essential for learning of unix
command (date, mkdir, chdir, cat, echo,cal).Experiment with these commands further to gain confidence
and proficiency in unix command.

2
EXPERIMENTNO:2
AIM: Write shell scripts to do the following:

a. Display OS version, release number, kernel version

b. Display top10 processes in descending order

c. Display processes with highest memory usage.

d. Display current logged in user and log name.


e. Display current shell, home directory, operating system type, current path setting, current working
directory.
A. Display OS version, release number, kernel version.
PROGRAM
echo"OS Name \is:
uname:

echo"Release number is:

uname-a;

echo"Releasenumberis."un
ame-1:
Output

root@rajesh-optiplex-3020:--Ssh exp5.sh
OS Name is:
Linux

3
Release number is:

Linux rajesh-optiplex-3020 4.4.0-81-generic #104-Ubuntu SMP WedJun 14 08:17:06 UTC 2017


266_64 86_6436_4

GNU/Linux Release
numberis:4.4.0-81-

generic

root@rajesh-optiplex-3020:-

B. Display top 10processes in descending order


PROGRAM
Echo "Top 10 processes in decending order is:":

psaxl|head-n10

Output

root@rajesh-optiplex-3020:~$sh expl.sh
Top 10
processes in decending order is:

4
FUID PID PPIDPRI NI VSZRSSWCHAN STATE TTYTIMEScommand

4 0 1 0 20 0 121125692 - S ? 0:01 Ishin/initsplash

1 0 2 0 20 0 0 0 - S ? 0:00 [kthreadd]

1 0 3 2 20 0 0 0 - S ? 0:00 [ksoftinqd/0]

1 0 5 2 0-200 0 - S < ? 0:00[kworker0:0H]

1 0 7 2 20 0 0 0 - S ? 0:44 [reu_sched]

1 0 8 2 20 0 0 0 - S ? 0:00[reu_bh]

1 0 9 2 -100- 0 0 - S ? 0:00[migration/0]

5 0 10 2-100 - 0 0 - S ? 0:00[watchdog/0]

5 0 11 2-100 - 0 0 - S ? 0:00[watchdog/1]

5
C. Display processes with high est memory usage.

Program

echo"Displayprocesseswithhighestmemoryusage";ps

-eopid,ppid.cmd,%mem,%cpu--sort=-%memhead

Output

root@rajesh-optiplex3020:~$ gedit exp2.sh


root@rajesh-optiplex3020:~$ sh exp2.sh
Displayprocesses with highest memoryusage
PID PPID CMD %MEM %CPU

2227 1581 /usr/lib/firefox/firefox 15.9 3.3

5077 5059 /usr/lib/libreoffice/program 5.4 2.0

2222 1581 /usr/lib/x86_64-linux-gnu/z 4.3 0.0

2041 1581 compiz 4.0 0.5

2369 1581 /usr/bin/python3/usr/bin/u 3.1 0.0

980 872 /usr/lib/xorg/Xorg-core:0 2.6 0.7

1973 1816 /usr/bin/gnome-software-g 2.5 0.0

1989 1816 nautilus-n 1.7 0.1

2014 1581 /usr/lib/evolution/evolution 1.5 0.0

root@rajesh-optiplex3020:~$

6
D. Displaycurrent logged in userandlogname.
PROGRAM
echo"LOGGEDINUSERSARE:-\n";

who -u

echo"NUMBEROFLOGGEDINUSERSARE:-\n";

who-u|we-]

Output

root@rajesh-optiplex-3020:~$sh exp3.sh
LOGGED IN USERS ARE:-

E. Display current shell, home directory, operating system type, current path setting,
current working directory.

Program

echo“Currenthomedirectoryis:":
whoami
echo "Current operatingsystemtype
is:"uname
echo “Curent current workingdirectoryis:”
pwd

Output
root@rajesh-optiplex-3020:-shexp4.nh
Current home directory is:
root

Currentoperatingsystem typeis:
Linux

7
Currentcurrentworkingdirectoryis:
/home/root
root@majesh-optiplex-3020:-$

Conclusion: In this experiment we have successfully perform top 10 process in descending order, processes
with highest memory usage and current login user name.

8
EXPERIMENTNO: 3

AIM: Implement any one basic commands of Linux like is, cp, my and others using kernel APIs.

Implement "Is" command usingsystem calls


PROGRAM
include
<stdio.h>#include<fon
tl.h>#include<sys/stat.
h> #include
<dirent.h>
intmain(intarge,char*argv[])

DIR*dp:

struct dirent*sd:

dp = opendir(argv[1]);
while((sd=readdir(dp))!=NULL)
{

printf("%s\t",sd->d_name);

closedir(dp):

9
Output:

root@litmus:/home# gee lscmd.c


root@litmus:/home#.a.outdimame
f.txt f.e

Conclusion: Here we have studied and perform basic Linux commands cp, my and others using kernel APIs.
To learn how kernel work

10
EXPERIMENTNO:4

AIM: To write the program to implement the system calls getpid() and getppid().

PROGRAMCODING:
#include<stdio.h>

#include<unistd.h>
#include<stdlib.h>int
main( )
{

int pid;
pid=fork();
if(pid==-1)
{

perror(“forkfailed”);
exit(0);
}

if(pid==0)

printf(“\nChildprocessisunder execution”);

printf(“\n Process id of the child process is %d”, getpid());


printf(“\n Process id oftheparent processis %d”, getppid());
}

11
else

printf(“\nParentprocessisunderexecution”);

printf(“\nProcessidof theparentprocessis%d”,getpid());

printf(“\n Process id of thechild process in parent is%d”, pid());


printf(“\n Process id of the parent of parent is %d”, getppid());
}

return(0);

OUTPUT:

Child process is under execution Process


id of the child process is 9314 Process id
of the parent process is 9313Parent
process is under execution Process id of
the parent process is 9313
Process id ofthe childprocess in parent is 9314
Process id of the parent of parent is 2825

RESULT: Thus the program was executed and verified successfully.


Conclusion: In this experiment we perform the display the child process and their parent process.

12
EXPERIMENTNO:5(A)

AIM: Write a program to demonstrate the concept of non-preemptive scheduling


algorithms.
FIRSTCOMEFIRSTSERVE:
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
main()
{

intbt[20],wt[20],tat[20],i,n; float
wtavg, tatavg;
clrscr();

printf("\nEnterthenumberofprocesses -- ");
scanf("%d", &n);
for(i=0;i<n;i++)

printf("\nEnterBurstTime forProcess %d --",i);


scanf("%d", &bt[i]);}
wt[0] = wtavg = 0;
tat[0]=tatavg=bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];tat[i]

13
= tat[i-1]+bt[i];wtavg

=wtavg+wt[i];

tatavg=tatavg+ tat[i];}

printf("\t PROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");

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

printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i],wt[i],tat[i]);


printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
getch();}
INPUT:

Enter the number of processes -- 3


EnterBurstTimeforProcess 0 --24
Enter Burst Time for Process 1 -- 3
Enter Burst Time for Process 2 – 3

OUTPUT:

PROC BURST WAITING TURNAROUND


ESS TIME TIME TIME

P0 24 0 24

P1 3 24 27

P2 3 27 30

Average Waiting Time-- 17.000000


AverageTurnaroundTime-- 27.000000

14
EXPERIMENT NO: 5(B)

AIM: Write a program to demonstrate the concept of preemptive scheduling Algorithms.

ROUNDROBIN:

SOURCECODE
#include<stdio.h>
main()
{
inti,j,n,bu[10],wa[10],tat[10],t,ct[10],max;float
awt=0,att=0,temp=0;
clrscr();
printf("Entertheno of processes--"); scanf("%d",&n);
for(i=0;i<n;i++)

{
printf("\nEnterBurst Time forprocess %d --", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnterthe size oftimeslice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])

max=bu[i];for(j=0;j<(max/t)+1;j++)for(i=0;i<n;i++)if(bu[i]!=0)
if(bu[i]<=t) {

15
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else {
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++){
wa[i]=tat[i]-
ct[i];att+=tat[i];
awt+=wa[i];}
printf("\nTheAverage Turnaround timeis --%f",att/n);
printf("\nThe Average Waiting time is -- %f ",awt/n);
printf("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");

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

printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);


getch();}
INPUT:

Enterthe noof processes–3


EnterBurstTimeforprocess1–24

EnterBurstTime forprocess 2--3Enter


Burst Time for process 3 – 3Enter the
size of time slice – 3

16
OUTPUT:

PROCESS BURSTTIME WAITING TIME TURNAROUNDTIME

0 24 6 30

1 3 4 7

2 3 7 10

TheAverage Turnaround time is – 15.666667 The


Average Waiting time is ---------------- 5.666667

Conclusion: Here we have successfully studied and perform the non-premptive process scheduling and
preemptive scheduling algorithm. Some time preemptive scheduling algorithm is give better response and vice
versa. It all depends on how a scheduling algorithm increases CPU utilization while decreasing average
process waiting time.

17
EXPERIMENTNO:6

AIM: Write a C program to implement solution of Producer consumer problem through Semaphore.

ALGORITHM:

Step1:The Semaphore mutex,full& empty are initialized.

Step2:In the case of producer process

1. Produce an item into temporary variable.

2. If there is empty space in the buffer check the mutex value for enter into the critical section.

3. If the mutex value is 0, allow the producer to add value in thetemporaryvariable to the
buffer.

Step3:In the case of consumer process

i) It should wait if the buffer is empty

ii) If there is anyitem in the buffer check for mutex value, ifthe mutex==0, removeitem from
buffer

iii) Signal the mute x value and reduce the empty value by 1.

iv) Consume the item.

Step4:Print the result

18
PROGRAMCODING:

#include<stdio.h>

intmutex=1,full=0,empty=3,x=0;
main()
{

intn;

void producer();
void consumer();
int wait(int);
intsignal(int);
printf("\n1.producer\n2.consumer\n3.exit\n");while(1)
{

printf(" \nenterur choice");


scanf("%d",&n);switch(n)
{

case 1:
if((mutex==1)&&(empty!=0))
producer();
else

printf("bufferisfull\n");
break;
case2:if((mutex==1)&&(full!=0))
consumer();
else

printf("bufferisempty");
break;

19
case 3:
exit(0);
break;
}
}
}
intwait(ints)

{
return(--s);
}
intsignal(ints)
{
return(++s);
}
voidproducer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\n producerproducestheitems %d",x);
mutex=signal(mutex);
}
voidconsumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\nconsumerconsumestheitem%d",x);x--);

mutex=signal(mutex);
}
20
RESULT : Thus the program was executed successfully
OUTPUT :
[cse6@localhost Pgm]$ccex11.c-oex11.out
[cse6@localhost Pgm]$ ./ex11.out
Produced element a
Consumedelementa
Produced element b
Consumedelementb
Produced element c
Consumedelementc
Produced element d
Consumedelementd
Produced element e
Consumedelemente
Produced element f
Consumed element f
Produced element g
Consumedelementg
Produced element h
Consumedelementh

Conclusion: Here we have successfully executed Producer Consumer problem.

21
EXPERIMENTNO:7(A)

AIM:A)Write a program to demonstrate the concept of deadlock avoidance through Banker's Algorithm

ALGORITHM:

Step1:StarttheProgram

Step 2: Obtain the required data through char and in data types.
Step 3: Enter the filename, index block.
Step4:Printthefilenameindexloop.

Step5:Fileisallocatedto theunusedindexblocks

Step 6: This is allocated to theunused linked allocation.


Step 7: Stop the execution

//DeadlockDetection algorithm implementation


#include <stdio.h>
#include<conio.h>
void main()
{

intfound,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;clrscr();
printf("Enter total no of processes");
scanf("%d",&tp);
printf("Entertotalnoofresources");
scanf("%d",&tr);
printf("Enterclaim(Max. Need)matrix\n");
for(i=1;i<=tp;i++)

22
{

printf("process%d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("Enterallocationmatrix\n");
for(i=1;i<=tp;i++)
{
printf("process%d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
printf("Enter resource vector (Total resources):\n");
for(i=1;i<=tr;i++)
{

scanf("%d",&r[i]);
}
printf("Enter availability vector (available resources):\n");
for(i=1;i<=tr;i++)
{
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=tp;i++)
{
sum=0;
for(j=1;j<=tr;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i;
23
k++;
}
}
for(i=1;i<=tp;i++)
{
for(l=1;l<k;l++)
if(i!=m[l])
{
flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
{
flag=0;
break;
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are:");
for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
24
printf("%d\t",j);
}
getch();
}

OUTPUT:

Enter total no. of processes :4


Enter total no. of resources : 5
Enter claim (Max. Need) matrix :01
001
00101
00001
10101
Enter allocation matrix:
10110
11000
00010
00000
Enter resource vector (Total resources) :21
121
Enter availability vector (available resources):00
001
Deadlock causing processes are: 2 3
RESULT:

Thus the program was executed successfully.

25
EXPERIMENTNO:7(B)

AIM: B) Write a program demonstrate the concept of DiningPhilospher's Problem.


PROGRAM:
inttph,philname[20], status[20],howhung,hu[20],cho;main()

{
inti; clrscr();

printf("\n\nDININGPHILOSOPHERPROBLEM");
printf("\nEnterthetotalno. ofphilosophers: ");
scanf("%d",&tph);
for(i=0;i<tph;i++)
{
philname[i]=(i+1);status[i]=1;
}
printf("Howmanyarehungry: ");
scanf("%d", &howhung);
if(howhung==tph)
{
printf(“\n All arehungry..\nDeadlock stage will occur”);
printf(\n”Exiting\n”);
else{
for(i=0;i<howhung;i++){
printf(“Enterphilosopher%dposition:”,(i+1));
scanf(“%d”,&hu[i]);
status[hu[i]]=2;

}
do

26
{
printf("1.Onecaneatatatime\t2.Twocan eatatatime
\t3.Exit\nEnter your choice:");
scanf("%d",&cho);switch(cho)
{
case1:one();
break;
case2:two();
break;
case3:exit(0);
default: printf("\nInvalidoption..");
}
}
while(1);
}
}
one()
{
intpos=0,x,i;
printf("\nAllow one philosopherto eat at anytime\n");
for(i=0;i<howhung; i++, pos++)
{
printf("\nP %d is granted to eat", philname[hu[pos]]);
for(x=pos;x<howhung;x++)

printf("\nP %d iswaiting",philname[hu[x]]);

}
}
two()
{
int i,j,s=0, t, r, x;
printf("\nAllowtwophilosopherstoeatatsame
27
time\n");for(i=0;i<howhung;i++)
{
for(j=i+1;j<howhung;j++)
{
if(abs(hu[i]-hu[j])>=1&&abs(hu[i]-hu[j])!=4)
{
printf("\n\ncombination%d\n",(s+1));
t=hu[i];
r=hu[j];s++;
printf("\nP %d and P %d are granted to eat", philname[hu[i]],
philname[hu[j]]);
for(x=0;x<howhung;x++)
{
if((hu[x]!=t)&&(hu[x]!=r))
printf("\nP %d iswaiting",philname[hu[x]]);
}
}

INPUT:

DINING PHILOSOPHER PROBLEM

Enter the total no.of philosophers: 5


How many are hungry : 3
Enterphilosopher1position:2

Enterphilosopher2position:4

Enter philosopher 3position:5


OUTPUT:
1.Onecan eatatatime2.Twocan
28
eat at a time 3.Exit Enter your choice: 1
Allow one philosopher to eat at anytimeP3
is granted to eat
P3is waiting P5
is waiting P 0 is
waiting
P5is grantedtoeatP5 is
waiting
P0iswaiting
P0isgrantedtoeatP0 is
waiting
1.One can eat at a time 2.Two can eat at a time 3.Exit
Enter your choice: 2
Allow two philosophers to eat at same time

combination1

P3andP5aregrantedtoeatP0 is
waiting

combination2
P3andP0aregrantedtoeatP5 is
waiting
combination3

P5andP0aregrantedtoeatP3 is
waiting
1. One can eatatatime2.Twocan
eatatatime3.ExitEnteryourchoice:3

Conclusion: In this experiment we have perform deadlock detection using Banker’s algorithm and Dining
Philospher's Problem. Hence successfully perform Banker’s algorithm and Dining Philospher's Problem.
29
EXPERIMENTNO:8(A)

AIM:A)Write a program to demonstrate the concept of MVT and MFT memory management
techniques.

PROGRAM(MVT):

#include<stdio.h>
#include<conio.h>
main()
{
int ms, bs, nob, ef,n,
mp[10],tif=0;inti,p=0;
clrscr();
printf("Enterthetotal memoryavailable (in Bytes) --");
scanf("%d",&ms);
printf("Entertheblocksize (in Bytes)-- "); scanf("%d",
&bs);
nob=ms/bs;ef=ms

-nob*bs;

printf("\nEnterthenumberofprocesses -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter memoryrequired for process %d (in Bytes)-- ",i+1);
scanf("%d",&mp[i]);
}

30
printf("\nNo. of Blocks available in memory--%d",nob);

printf("\n\nPROCESS\tMEMORYREQUIRED\tALLOCATED\tINTERNALFRAGMENTATION");

for(i=0;i<n &&p<nob;i++)
{
printf("\n%d\t\t%d",i+1,mp[i]);
if(mp[i] > bs)
printf("\t\tNO\t\t---");
else
{
printf("\t\tYES\t%d",bs-mp[i]);
tif = tif + bs-mp[i];
p++;

}
}

if(i<n)
printf("\nMemoryis Full, Remaining Processes cannot be accomodated");
printf("\n\nTotal Internal Fragmentation is %d",tif);
printf("\nTotal External Fragmentationis %d",ef);
getch();
}

INPUT

Enter thetotal memoryavailable (in Bytes) -- 1000


Enter the block size (in Bytes)-- 300
Enterthe numberofprocesses–5

31
Enter memory required for process 1 (in Bytes) -- 275
Enter memory required for process 2 (in Bytes)--400

Enter memory required for process 3 (in Bytes) -- 290


Enter memory required for process 4 (in Bytes) -- 293
Enter memory required for process 5 (in Bytes) -- 100No.
of Blocks available in memory -- 3

OUTPUT

PROCESS MEMORY ALLOCATED INTERNAL


REQUIRED
FRAGMENTATION
1 275 YES 25
2 400 NO ----
3 290 YES 10
4 293 YES 7
Memory is Full, Remaining Processes cannot be accommodated Total
Internal Fragmentation is 42
TotalExternalFragmentationis100

PROGRAM(MFT):

#include<stdio.h>
#include<conio.h>
main()
{
int ms,mp[10],i,
temp,n=0;charch='y';
clrscr();

32
printf("\nEnterthetotal memoryavailable (in Bytes)-- ");
scanf("%d",&ms);
temp=ms;
for(i=0;ch=='y';i++,n++)

{
printf("\nEnter memoryrequired for process %d (in Bytes) -- ",i+1);
scanf("%d",&mp[i]);
if(mp[i]<=temp)
{
printf("\nMemoryis allocated for Process %d ",i+1);
temp = temp - mp[i];
}
else
{
printf("\nMemoryisFull");break;
}
printf("\nDo you wantto continue(y/n)--");
scanf(" %c", &ch);

}
printf("\n\nTotal Memory Available -- %d", ms);
printf("\n\n\tPROCESS\t\t MEMORY ALLOCATED ");
for(i=0;i<n;i++)
printf("\n \t%d\t\t%d",i+1,mp[i]);
printf("\n\nTotal MemoryAllocated is %d",ms-temp);
printf("\nTotal External Fragmentation is %d",temp);
getch();
}

33
OUTPUT:
Enter the total memory available (in Bytes) – 1000
Enter memory required for process 1 (in Bytes)– 400
Memory is allocated for Process 1

Do you want to continue(y/n)--y


Enter memory required for process 2 (in Bytes) -- 275
Memory is allocated for Process 2
Do you want to continue(y/n)–y
Enter memory required for process 3 (in Bytes)– 550
Memory is Full
Total MemoryAvailable– 1000

PROCESS MEMORY
ALLOCATED
1 400
2 275
Total Memory Allocated is 675 Total
External Fragmentation is 325

Conclusion: Here we have learned and perform memory management technique. Here we also calculate
Internal fragmentation of process.

34
EXPERIMENTNO:8(B)

AIM: B) Write a program to demonstrate the concept of dynamic partitioningplacement algorithms i.e. Best
Fit, First Fit, Worst-Fit etc.

PROGRAM
WORST-FIT
#include<stdio.h>
#include<conio.h>#def
inemax25void main()
{

intfrag[max],b[max],f[max],i,j,nb,nf,t
emp; static int bf[max],ff[max];
clrscr();
printf("\n\tMemoryManagementScheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enterthenumber offiles:");
scanf("%d",&nf);
printf("\nEnterthe sizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enterthesizeofthefiles:-\n");

35
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();

36
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block2:2
Block3:7
Enterthesizeofthefiles:-
File 1: 1
File 2: 4
OUTPUT

FILENO. FILESIZE BLOCKNO. BLOCKSIZE FRAGMENT


1 1 1 5 4
2 4 3 7 3

37
BEST-FIT

#include<stdio.h>
#include<conio.h>#def
inemax25void main()
{

int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;static
int bf[max],ff[max];
clrscr();

printf("\nEnterthenumberof blocks:");
scanf("%d",&nb);
printf("Enterthenumber offiles:");
scanf("%d",&nf);
printf("\nEnterthe sizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
printf("Block%d:",i);

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

printf("Enterthe sizeofthe files:-\n");


for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{

38
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("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf&& ff[i]!=0;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();
}

INPUT
Enterthenumberofblocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block2:2

Block3:7

39
Enter the size of the files:-

File 1: 1
File2:4

OUTPUT

FILENO. FILESIZE BLOCKNO. BLOCKSIZE FRAGMENT


1 1 2 2 1
2 4 1 5 1

40
FIRST-FIT

#include<stdio.h>
#include<conio.h>#def
inemax25void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();

printf("\n\tMemoryManagementScheme - Worst Fit");


printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enterthenumber offiles:");
scanf("%d",&nf);
printf("\nEnterthe sizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);

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

printf("Enterthesizeofthefiles:-\n");for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);
}

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

41
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)//ifbf[j]isnotallocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
}
}
frag[i]=highest;bf[ff[i]]=1;highest=0;
}
ff[i]=j; highest=temp;
}

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();
}

INPUT
Enter the number ofblocks:3

Enter the number of files: 2


Enter the size of theblocks:-
Block 1: 5
Block2:2

Block3:7

42
Enterthesizeofthefiles:-
File 1: 1
File2:4

OUTPUT

FILENO. FILESIZE BLOCKNO. BLOCKSIZE FRAGMENT


1 1 3 7 6
2 4 1 5 1

Conclusion: Here we have perform different type of memory management technique like Best Fit, Worst Fit,
First Fit.and successfully calculate the entire algorithm.

43
EXPERIMENT NO: 9

AIM: Write a program in C demonstrate the concept of page replacement


policies for handling page faults eg: FIFO, LRU.

A) FIRSTINFIRSTOUT
SOURCE CODE :
#include<stdio.h>
#include<conio.h>i
nt fr[3]; void
main()
{

voiddisplay();
int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
intflag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++){
fr[i]=
-1;
}
for(j=0;j<12;j++)
{
flag1=0;flag2=0; for(i=0;i<12;i++){ if(fr[i]==page[j])
{
flag1=1;flag2=1;break;}}
if(flag1==0) {
for(i=0;i<frsize;i++) {
if(fr[i]==-1)
{

44
fr[i]=page[j];flag2=1;break;}}}
if(flag2==0) {
fr[top]=page[j];
top++;
pf++;if(top>=frsize)
top=0;
}
display();
}

printf("Numberof page faults :%d",pf+frsize);


getch();
}

voiddisplay()
{
int i; printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);
}

OUTPUT:
2 -1 -1
23-1
23-1
231

531

45
521
524
524

324
324
354
352

Number of page faults : 9

46
B) LEASTRECENTLYUSED
SOURCE CODE :
#include<stdio.h>
#include<conio.h>i
nt fr[3]; void
main()
{

voiddisplay();

int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
intindex,k,l,flag1=0,flag2=0,pf=0,frsize=3;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;

}
for(j=0;j<12;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])

{
flag1=1;flag2=1;
break;
}
}
if(flag1==0)

47
{
for(i=0;i<3;i++){
if(fr[i]== -1)
{
fr[i]=p[j];flag2=1;
break; }}}
if(flag2==0) {
for(i=0;i<3;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--
)
{
for(i=0;i<3;i++) {
if(fr[i]==p[k])fs[i]=1;
}
}
for(i=0;i<3;i++){
if(fs[i]==0)
index=i; }
fr[index]=p[j];
pf++; }
display();}
printf("
\nnoofpage faults:%d",pf+frsize);
getch(); }
void display() {
inti;printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i
]);
}
48
OUTPUT:

2-1 -1
23-1
23-1

231
251
251
254

254
354
352
352
352
No of page faults : 7

Conclusion: Here we have perform different type of Page replacement algorithm (FIFO,LRU) and FIFO
have 9 page fault and LRU have 7 page fault. Thus in this process LRU give the better result than FIFO.

49
EXPERIMENT NO: 10(A)

AIM: Write a C program to simulate File allocation strategies typically sequential, indexed and
linked files.

A. SEQUENTIAL:

SOURCECODE:

#include<stdio.h>
main()
{

intf[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
X:

printf("\n Enterthe startingblock &length of file"); scanf("%d%d",&st,&len);


for(j=st;j<(st+len);j++)
if(f[j]==0)
{

f[j]=1;

printf("\n%d->%d",j,f[j]);

50
else
{
printf("Block already allocated");

break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch();
}

OUTPUT:
Enter the starting block & length offile 4 10
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
The file is allocated to disk.

51
B. INDEXED:

SOURCECODE:

#include<stdio.h>
intf[50],i,k,j,inde[50],n,c,count=0,p;
main(){
clrscr();
for(i=0;i<50;i++)
f[i]=0;
x: printf("enterindex block\t");
scanf("%d",&p);if(f[p]==0)
{
f[p]=1;
printf("enterno offiles on index\t");
scanf("%d",&n); }else {
printf("Block already allocated\n");
gotox;
}
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
{
printf("Blockalreadyallocated");
goto x;
}
for(j=0;j<n;j++)
f[inde[j]]=1;

52
printf("\n allocated " );
printf("\n fileindexed");
for(k=0;k<n;k++)
printf("\n%d->%d:%d",p,inde[k],f[inde[k]]);

printf("Enter1 to enter morefiles and 0to exit\t");


scanf("%d",&c);
if(c==1)
goto x;
else
exit();
getch(); }
OUTPUT:
enterindexblock9

Enternooffilesonindex 31 2 3
Allocated
Fileindexed
9->1:1
9->2;1

9->3:1enter1to enter more files and 0 to exit

53
C. LINKED:

SOURCECODE:
#include<stdio.h>
main()
{
intf[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++)f[i]=0;

printf("Enter how many blocks that are already


allocated"); scanf("%d",&p);
printf("\nEnter the blocks no.s that are already allocated");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}

X:
printf("Enter the starting index block &
length");scanf("%d%d",&st,&len);k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}

54
else

{
printf("\n%d->file is already allocated" ,j);
k++;
}
}
printf("\n Ifuwanttoenterone
more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto
X;
else
exit();
getch();
}

OUTPUT:
Enter how many blocks that are already allocated 3 Enter the blocks no.s
that are already allocated 4 7 Enter the starting index block &length 3 7 9
3->1
4->1fileisalreadyallocated 5-
>1
6->1
7->1fileisalreadyallocated 8-
>1
9->1file isalreadyallocated

10->1
11->1
12->1

55
EXPERIMENT NO: 10(B)

AIM: Write a C program to simulate file organization of multi-level directory


structure.
PROGRAMCODING

#include<stdio.h>
#include<graphics.h>s
truct tree_element
{
charname[20];
int x,y,ftype,lx,rx,nc,level;
structtree_element*link[5];
};
typedeftructtree_element
node; void main()
{
intgd=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();

}
create(node**root,intlev,char*dname,intlx,intrx,intx)

56
{

int i,gap;
if(*root==NULL)
{

(*root)=(node*)malloc(sizeof(node));
printf("entername of dir/file(under %s):",dname); 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)
printf("Howmanyusers");
else
printf("hoe many files");
printf("(for%s):",(*root)->name);

scanf("%d",&(*root)->nc);
}
else(*root)->nc=0;

57
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,roo>y+10,0,0);
else

58
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]);

RESULT:

Thus the program was executed successfully.

59
EXPERIMENT NO: 10(C)

AIM: Write a program in C to do disk scheduling-FCFS, SCAN, C-SCAN.


A) FCFSDISKSCHEDULINGALGORITHM
#include<stdio.h>

main()

{
int t[20],n, I, j, tohm[20],tot=0; float avhm;
clrscr();
printf(“entertheno.oftracks”);
scanf(“%d”,&n);
printf(“enterthetracksto betraversed”);
for(i=2;i<n+2;i++)
scanf(“%d”,&t*i+);
for(i=1;i<n+1;i++)
{
tohm[i]=t[i+1]-t[i];
if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}
for(i=1;i<n+1;i++)
tot+=tohm[i];
avhm=(float)tot/n;
printf(“Tracks traversed\tDifference between tracks\n”);
for(i=1;i<n+1;i++)printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);

60
printf("\nAverage header movements:%f",avhm);
getch();
}

INPUT

Enterno.oftracks:9

Entertrackposition:5558 607018 90150 160 184OUTPUT


Track straversed Difference between tracks

55 45

58 3

60 2

70 10

18 52

90 72

150 60

160 10

184 24

Average header movements :30.888889

61
B) SCAN DISK SCHEDULING ALGORITHM

#include<stdio.h>
main()
{

int t[20], d[20], h,i, j, n,temp, k,atr[20], tot, p, sum=0; clrscr();

printf("enterthe no oftracks to betraveresed");


scanf("%d'",&n);
printf("entertheposition ofhead");
scanf("%d",&h);
t[0]=0;t[1]=h;

printf("enterthetracks");
for(i=2;i<n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<n+2;i++)
{
for(j=0;j<(n+2)-i-1;j++)
{
if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}
}
}

62
for(i=0;i<n+2;i++)
if(t[i]==h)
j=i;k=i;
p=0;

while(t[j]!=0)
{

atr[p]=t[j];j--;
p++;

}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverage header movements:%f",(float)sum/n);
getch();
}

INPUT

Enterno.oftracks:9
Entertrackposition:55586070 1890150160 184

63
OUTPUT

Track straversed Difference between tracks

150 50

160 10

184 24
90 94

70 20

60 10

58 2

55 3

18 37

Average header movements :27.77

64
C) C-SCAN DISK SCHEDULING ALGORITHM
#include<stdio.h>

main()

{
int t[20], d[20], h,i, j, n,temp, k,atr[20], tot, p, sum=0; clrscr();
printf("enterthe no oftracks to betraveresed");
scanf("%d'",&n);
printf("entertheposition ofhead");
scanf("%d",&h);
t[0]=0;t[1]=h;
printf("entertotaltracks");
scanf("%d",&tot);
t[2]=tot1;

printf("enter the tracks");


for(i=3;i<=n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<=n+2;i++)
for(j=0;j<=(n+2)-i-1;j++)

if(t[j]>t[j+1])
{
temp=t[j];

t[j]=t[j+1];
t[j+1]=temp
}
for(i=0;i<=n+2;i++)
if(t[i]==h);j=i;break;
p=0;

65
while(t[j]!=tot-1)
{
atr[p]=t[j];
j++;
p++;
}
atr[p]=t[j];
p++;
i=0;
while(p!=(n+3)&&t[i]!=t[h])
{
atr[p]=t[i];i++;
p++;
}
Page67for(j=0;j<n+2;j++)
{
if(atr[j]>atr[j+1])

d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];}
printf("total header movements%d",sum);
printf("avg is %f",(float)sum/n); getch();}
INPUT

Enterthe track position :55 58 6070 18 90150 160 184


Enter starting position : 100

66
OUTPUT
Tracks traversed Difference Between tracks

150 50

160 10

184 24

18 240

55 37

58 3

60 2

70 10

90 20

Averageseektime:35.7777779

Conclusion: In this experiment we have studied and successfully perform various types of File management
techniques and calculate the seek time of all the techniques.

THANKYOU!

67

You might also like