OS_LAB_MANUAL CSE-2024-25
OS_LAB_MANUAL CSE-2024-25
OS_LAB_MANUAL CSE-2024-25
LABORATORYMANUAL
BRANCH :
BATCH :
VISION:
MISSION:
1. Concepts of Computing Discipline: To educate students at undergraduate, postgraduate and doctoral levels
in the fundamental and advanced concepts of computing discipline.
2. Quality Research: To provide strong theoretical and practical background across the Computer Science and
Engineering discipline with the emphasis on computing technologies, quality research, consultancy, and
trainings.
3. Continuous Teaching Learning: To promote a teaching learning process that brings advancements in
Computer Science and Engineering discipline leading to new technologies and products.
4. Social Responsibility and Ethical Values: To inculcate professional behavior, innovative research
Capabilities, leadership abilities and strong ethical values in the young minds so as to work with the commitment
for the betterment of the society
PROGRAMEDUCATIONALOBJECTIVES(PEOs):
PEO1: Current Industry Practices: Graduates will analyze real world problems and give solution using current
industry practices in computing technology.
PEO2: Research and Higher Studies: Graduates with strong foundation in mathematics and engineering
fundamentals that will enable graduates to pursue higher learning, R&D activities and consultancy.
PEO3: Social Responsibility: Graduates will be professionals with ethics, who will provide industry growth and
social transformation as responsible citizens.
PEO4: Entrepreneur: Graduates will be able to become entrepreneur to address social, technical and business
challenges.
PROGRAMOUTCOMES(POs):
Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
Problem analysis: Identify, formulate, research literature, and analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences.
2
OPERATING SYSTEMS [MVJ22CS32]
Design/development of solutions: Design solutions for complex engineering 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 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 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 contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering
practice.
Environment and sustainability: Understand the impact of the professional engineering solutions in societal
and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
Engineering practice.
Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams,
and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering 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 engineering and
Management principles and apply these to one’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 engage in independent and
life-long learning in the broadest context of technological change.
PROGRAMSPECIFICOUTCOMES(PSOs):
3
OPERATING SYSTEMS [MVJ22CS32]
PSO2:PracticalSolution:Abilitytopracticallyprovidesolutionsforrealworldproblemswith a
broad range of programming language and open-source platforms in various
computingdomains.
PSO3: Research: Ability to use innovative ideas to do research in various domains to
solvesocietalproblems.
4
OPERATING SYSTEMS [MVJ22CS32]
COURSEOBJECTIVES:
• Foundation knowledge in database concepts, technology and practice to groom
studentsintowell-informed databaseapplicationdevelopers.
• StrongpracticeinSQLprogramming through avariety ofdatabase problems.
• Develop database applications using front-end tools and back-end DBMS.
PREREQUISITES:
COURSEOUTCOMES(CO’s):
At the end of the course, the student will be able to:
CO 1. Explain the structure and functionality of operating system
CO 2. Apply appropriate CPU scheduling algorithms for the given problem.
CO 3. Analyze the various techniques for process synchronization and deadlock handling.
CO 4. Apply the various techniques for memory management
CO 5. Explain file and secondary storage management strategies. CO 6. Describe the need for information
protection mechanisms
5
OPERATING SYSTEMS [MVJ22CS32]
CONTENTS
Sl.N Experiments
O
1 Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process,
terminate process)
2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a)
FCFS
b) SJF c) Round Robin d) Priority.
3 Develop a C program to simulate producer-consumer problem using semaphores.
CIE for the theory component of the IPCC (maximum marks 50)
1. IPCC means practical portion integrated with the theory of the course.
2. CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.
25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests, each of 15
Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods
6
OPERATING SYSTEMS [MVJ22CS32]
mentioned in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second test after
covering 85-90% of the syllabus.
1. Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the
theory component of IPCC (that is for 25 marks).
2. The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.CIE
for the practical component of the IPCC
3. 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks for
the test to be conducted after the completion of all the laboratory sessions.
4. On completion of every experiment/program in the laboratory, the students shall be evaluated including
viva-voce and marks shall be awarded on the same day.
5. The CIE marks awarded in the case of the Practical component shall be based on the continuous
evaluation of the laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all
experiments’ write-ups are added and scaled down to 15 marks.
6. The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted
for 50 marks and scaled down to 10 marks.
7. Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory
component of IPCC for 25 marks.
The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCCSEE
for IPCCTheory SEE will be conducted by University as per the scheduled timetable, with common
question papers for the course (duration 03 hours)[The question paper will have ten questions. Each question
is set for 20 marksThere will be 2 questions from each module. Each of the two questions under a module (with
a maximum of 3 sub-questions), should have a mix of topics under that moduleThe students have to answer 5
full questions, selecting one full question from each module]Marks scoredby the student shall be proportionally
scaled down to 50 Marks]The theory portion of the IPCC shall be for both CIE and SEE, whereas the
practical portion will have a]CIE component only. Questions mentioned in the SEE paper may include
questions from the practical component
7
OPERATING SYSTEMS [MVJ22CS32]
INTRODUCTION TO UNIX
AIM:
To study about the basics of UNIX
UNIX:
It is a multi-user operating system. Developed at AT& T Bell Industries, USA in 1969.
Ken Thomson along with Dennis Ritchie developed it from MULTICS (Multiplexed Information
and Computing Service) OS.
By1980, UNIX had been completely rewritten using C language.
LINUX:
It is similar to UNIX, which is created by Linus Torualds. All UNIX commands works in Linux. Linux
is a open source software. The main feature of Linux is coexisting with other OS such as windows
and UNIX.
STRUCTURE OF A LINUXSYSTEM:
It consists of three parts.
UNIX kernel
Shells
Tools and Applications
UNIX KERNEL:
Kernel is the core of the UNIX OS. It controls all tasks, schedule all Processes and carries out all the functions
of OS.
SHELL:
Shell is the command interpreter in the UNIX OS. It accepts command from the user and analyses and
interprets them
AIM:
To study of Basic UNIX Commands and various UNIX editors such as vi, ed, ex and EMACS.
CONTENT:
Note: Syn->Syntax
date
–used to check the date and time Syn:$date
Format Purpose Example Result
+%m To display only month $date+%m 06
+%h To display month name $date+%h June
+%d To display day of month $date+%d O1
+%y To display last two digits of years $date+%y 09
+%H To display hours $date+%H 10
+%M To display minutes $date+%M 45
+%S To display seconds $date+%S 55
cal
–used to display the calendar Syn:$cal 2 2009
echo
–used to print the message on the screen.
Syn:$echo “text”
ls
–used to list the files. Your files are kept in a directory.
Syn:$lsls–s
lp
–used to take printouts Syn:$lp filename
man
–used to provide manual help on every UNIX commands.
Syn:$man unix command
$man cat
who &whoami
–it displays data about all users who have logged into the system currently. The next command displays about current
user only.
Syn:$who$whoami
uptime
–tells you how long the computer has been running since its last reboot or power-off.
Syn:$uptime
uname
–it displays the system information such as hardware platform, system name and processor, OS type.
Syn:$uname–a
hostname
–displays and set system host name Syn:$ hostname
bc
–stands for „best calculator‟
$bc $ bc $ bc $ bc
10/2*3 scale =1 ibase=2 sqrt(196)
15 2.25+1 obase=16 14 quit
3.35 11010011
quit 89275
1010
Ā
Quit
$bc $ bc-l
for(i=1;i<3;i=i+1)I scale=2
1 s(3.14)
2 0
3 quit
Viewing:
Syn:$cat filename
Add text to an existing file:
Syn:$cat>>filename
DEPARTMENT OF CSE, MVJCE 10 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)
grep–used to search a particular word or pattern related to that word from the file. Syn:$grep search word filename
Eg:$grep anu student
cp–copies the files or directories Syn:$cpsource file destination file Eg:$cp student stud
mv–to rename the file or directory syn:$mv old file new file
Eg:$mv–i student student list(-i prompt when overwrite)
cut–it cuts or pickup a given number of character or fields of the file. Syn:$cut<option><filename>
Eg: $cut –c filename
$cut–c1-10emp
$cut–f 3,6emp
$ cut –f 3-6 emp
-c cutting columns
-f cutting fields
Examples:
$chmodu-wx student
Removes write and execute permission for users
$chmodu+rw,g+rwstudent
Assigns read and write permission for users and groups
$chmodg=rwx student
Assigns absolute permission for groups of all read, write and execute permissions
wc–it counts the number of lines, words, character in a specified file(s) with the options as –l,-w,-c
UNIX EDITORS
AIM:
To study of various UNIX editors such as vi, ed, ex and EMACS.
CONCEPT:
Editor is a program that allows user to see a portions a file on the screen and modify characters and
lines by simply typing at the current position. UNIX supports variety of Editors.
They are:vi,ed,ex,EMACS
Vi- vi is stands for “visual”.vi is the most important and powerful editor.vi is a full screen editor that allows
user to view and edit entire document at the same time.vi editor was written in the University of California,
at Berkley by Bill Joy, who is one of the co-founder of Sun Microsystems.
Features of vi:
It is easy to learn and has more powerful features.
Itworksgreatspeedandiscasesensitive.vihaspowerfulundofunctionsandhas3modes:
Command mode
Insert mode
Escape or ex mode
In command mode, no text is displayed on the screen.
In Insert mode, it permits user to edit insert or replace text. In escape mode, it displays commands at command line.
Moving the cursor with the help of h, l, k, j, I, etc
EMACS Editor
Motion Commands:
M-> Move to end of file
M-< Move to beginning of file
C-v Move forward a screen M –v Move backward a screen C –n Move to next line C-p Move to previous line
C-a Move to the beginning of the line C-e Move to the end of the line
C-f Move forward a character C-b Move backward a character M-f Move forward a word
M-b Move backward a word
Deletion Commands:
DELdelete the previous character C -d delete the current character M -DEL delete the previous word
M-ddelete the next word
C-x DELdeletes the previous sentence
M-kdelete the rest of the current sentence
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
main(void) {
pid_tpid = 0;
pid = fork();
if (pid == 0) {
printf("I am the child.\\n");
}
if (pid> 0) {
printf("I am the parent, the child is %d.\\n", pid);
}
if (pid< 0) {
perror("In fork():");
}
exit(0);
}
2. Simulate the following CPU scheduling algorithms to find turnaround time and waiting time
a) FCFS
b) SJF
c) Round Robin
d)Priority.
#include<stdio.h>
#include<conio.h>
main()
intbt[20],wt[20],tat[20],i,n;floa
twtavg,tatavg;
clrscr();
for(i=0;i<n;i++)
printf("\nEnterBurstTimeforProcess%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]=tat[i-
1]+bt[i];wtavg=wtavg+w
t[i];tatavg=tatavg+ tat[i];
printf("\tPROCESS \tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)
printf("\n\tP%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("\nAverageTurnaroundTime--
%f",tatavg/n);getch();
INPUT
Enterthenumberofprocesses-- 3
EnterBurstTimeforProcess0-- 24
EnterBurstTimeforProcess1 -- 3
EnterBurstTimeforProcess2-- 3
OUTPUT
PROCESS BURSTTIME WAITINGTIME TURNAROUND
TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
AverageWaitingTime-- 17.000000
AverageTurnaroundTime-- 27.000000
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
main()
intp[20],bt[20],wt[20],tat[20],i,k,n,temp;floatwtavg,tatavg;
clrscr();
for(i=0;i<n;i++)
p[i]=i;
for(i=0;i<n;i++)for(
k=i+1;k<n;k++)if(b
t[i]>bt[k])
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k];p
[k]=temp;
wt[0]=wtavg=0;
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-
1]+bt[i];wtavg = wtavg +
wt[i];tatavg =tatavg+
tat[i];
printf("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)
getch();
INPUT
Enterthenumberofprocesses-- 4
EnterBurstTimeforProcess0-- 6
EnterBurstTimeforProcess1-- 8
EnterBurstTimeforProcess2-- 7
EnterBurstTimeforProcess3-- 3
OUTPUT
PROCESS BURST WAITING TURNARO
TIME TIME UNDTIME
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
AverageWaitingTime -- 7.000000
AverageTurnaroundTime-- 13.000000
SOURCECODE
#include<stdio.h>
main()
int
i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
floatawt=0,att=0,temp=0;
clrscr();
printf("Enterthenoofprocesses--
");scanf("%d",&n);
for(i=0;i<n;i++)
printf("\nEnterBurstTimeforprocess%d--
",i+1);scanf("%d",&bu[i]);
DEPARTMENT OF CSE, MVJCE 19 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
ct[i]=bu[i];
printf("\nEnterthesizeoftimeslice--
");scanf("%d",&t);
max=bu[0];for(i=1;i<n;i
++)if(max<bu[i])max=b
u[i];for(j=0;j<(max/t)+1;
j++)for(i=0;i<n;i++)if(b
u[i]!=0)
if(bu[i]<=t)
{ta
t[i]=temp+bu[i];te
mp=temp+bu[i];b
u[i]=0;
else{bu[i]=b
u[i]-
t;temp=temp+
t;
for(i=0;i<n;i++){
wa[i]=tat[i]-
ct[i];att+=tat[i];awt
+=wa[i];}
printf("\nTheAverageTurnaroundtimeis--
%f",att/n);printf("\nTheAverageWaitingtimeis--%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:
Enterthenoofprocesses–3
Enter Burst Time for process 1 –
24EnterBurstTimeforprocess2--
3EnterBurstTimeforprocess3–
3Enterthesize oftimeslice–3
OUTPUT:
PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME
1 24 6 30
2 3 4 7
3 3 7 10
TheAverageTurnaroundtimeis–
15.666667TheAverageWaitingtimeis5.666667
SOURCECODE:
#include<stdio.h>
main()
intp[20],bt[20],pri[20],wt[20],tat[20],i,k,n,temp;floatwtavg,tatavg;
clrscr();
printf("Enterthenumberofprocesses---
");scanf("%d",&n);
for(i=0;i<n;i++){
p[i]= i;
printf("EntertheBurstTime&PriorityofProcess%d---",i);scanf("%d
%d",&bt[i],&pri[i]);
for(i=0;i<n;i++)for(
k=i+1;k<n;k++)if(p
ri[i]
>pri[k]){temp=p[i];
p[i]=p[k];p[k]=tem
p;temp=bt[i];bt[i]=
bt[k];bt[k]=temp;te
mp=pri[i];pri[i]=pri
[k];pri[k]=temp;
wtavg=wt[0]=0;tatavg
= tat[0] =
bt[0];for(i=1;i<n;i++)
wt[i]=wt[i-1] +bt[i-1];
tat[i] =tat[i-1]+bt[i];
wtavg=wtavg+wt[i];tata
vg =tatavg+ tat[i];
printf("\nPROCESS\t\tPRIORITY\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME"
);
for(i=0;i<n;i++)
getch();
INPUT
Enterthenumberofprocesses–5 3
EntertheBurstTime&PriorityofProcess 0---10
EntertheBurstTime&PriorityofProcess 1---1 1
EntertheBurstTime&PriorityofProcess 2---2 4
EntertheBurstTime&PriorityofProcess 3---1 5
EntertheBurstTime&PriorityofProcess 4---5 2
OUTPUT
PROCESS PRIORITY BURSTTIME WAITI TURNARO
NG UND
1 1 1 TIME0 TIME1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19
AverageWaitingTimeis--- 8.200000
AverageTurnaroundTimeis------------------- 12.000000
#include<stdio.h
>
voidmain()
intbuffer[10],bufsize,in,out,produce,consume,choice=
0;in=0;
out=0;
bufsize=10;
while(choice!=3)
scanf(“%d”,&choice);
switch(choice){
case1:if((in+1)%bufsize==out)
printf(“\nBufferisFull”);
else
{ printf(“\nEnterthevalue:“);s
canf(“%d”,&produce);buffe
r[in]= produce;
in=(in+1)%bufsize;
break;;;
case2: if(in==out)
printf(“\nBufferisEmpty”);
} } }
else
consume=buffer[out];
out = (out+1)%bufsize;
}}
break;
OUTPUT
1.Produce 2.Consume 3.
ExitEnteryourchoice:2
BufferisEmpty
1.Produce 2.Consume 3.
ExitEnteryourchoice:1
Enterthevalue:100
1.Produce 2.Consume 3.
ExitEnteryourchoice:2
Theconsumedvalueis100
1.Produce 2.Consume 3.
ExitEnteryourchoice:3
4.Develop a C program which demonstrates inter process communication between a reader process
and a writer process. Use mkfifo,open, read,write and close APIs in your program.
/*WriterProcess*/
#include <stdio.h>#include
<fcntl.h>#include
<sys/stat.h>#include
<sys/types.h>#include<unistd.h>
intmain()
int fd;
char buf[1024];
printf("RunReaderprocesstoreadtheFIFOFile\n");fd=open(myfifo,
O_WRONLY);
write(fd,"Hi",sizeof("Hi"));
/*write"Hi"totheFIFO*/close(fd);
/*ReaderProcess*/
#include <fcntl.h>#include
<sys/stat.h>#include
<sys/types.h>#include
<unistd.h>#include<stdio.h>
int fd;
charbuf[MAX_BUF];
read(fd, buf,
MAX_BUF);printf("Writer:%s\n",buf);
close(fd);
return 0;
#include<stdio.h>
#include<conio.h>
voidmain()
charjob[10][10];
inttime[10],avail,tem[10],temp[10];intsafe[10];i
nt ind=1,i,j,q,n,t;
clrscr();
printf("Enternoofjobs:");sca
nf("%d",&n);for(i=0;i<n;i+
+)
for(i=0;i<n;i++)
temp[i]=time[i];
tem[i]=i;
for(i=0;i<n;i++)fo
r(j=i+1;j<n;j++)
if(temp[i]>temp[j])
t=temp[i];
temp[i]=temp[j];
temp[j]=t;t=tem[i];
tem[i]=tem[j];
tem[j]=t;
for(i=0;i<n;i++)
q=tem[i];if(time[
q]<=avail)
safe[ind]=tem[i];avail=ava
il-
tem[q];printf("%s",job[safe
[ind]]);ind++;
else
printf("Nosafesequence\n");
printf("Safesequenceis:");f
or(i=1;i<ind;i++)
printf("%s
%d\n",job[safe[i]],time[safe[i]]);getch();
OUTPUT:
Enter noofjobs:4
Enter name and time: A
1Enter name and time: B
4Enter name and time: C
2Enternameandtime:D3
Enter the available resources:
20Safesequenceis:A1,C2,D3,B4.
PROGRAM
WORST-FIT
#include<stdio.h>
#include<conio.h>
#define max
25voidmain()
intfrag[max],b[max],f[max],i,j,nb,nf
,temp;staticintbf[max],ff[max];clrsc
r();
scanf("%d",&nb);
printf("Enterthenumberoffiles:");scanf("
%d",&nf);
printf("Block%d:",i);
scanf("%d",&b[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();
INPUT
Enterthenumberofblocks:3En
terthenumberoffiles: 2
Enterthesizeoftheblocks:-
Block1:5
Block2: 2
Block3: 7
Enterthesizeofthefiles:-File
1:1
File2:4
OUTPUT
FileNo FileSize BlockNo BlockSize Fragment
1 1 1 5 4
2 4 3 7 3
BEST-FIT
#include<stdio.h>
#include<conio.h>
#define max
25voidmain()
intfrag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;sta
ticintbf[max],ff[max];
clrscr();
printf("\nEnterthenumberofblocks:");scanf("%d",&nb)
;
printf("Enterthenumberoffiles:");scanf("
%d",&nf);
printf("Block%d:",i);
scanf("%d",&b[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]);ge
tch();
INPUT
Enterthenumberofblocks:3
Enterthenumberoffiles: 2
Enterthesizeoftheblocks:-
Block1:5
Block2: 2
Block3: 7
Enterthesizeofthefiles:-File
1:1
File2:4
OUTPUT
FileNo FileSize Block No BlockSize Fragment
1 1 2 2 1
2 4 1 5 1
FIRST-FIT
#include<stdio.h>
#include<conio.h>
#define max
25voidmain()
intfrag[max],b[max],f[max],i,j,nb,nf,temp,highe
st=0;staticintbf[max],ff[max];
clrscr();
printf("\n\tMemoryManagementScheme-
WorstFit");printf("\nEnterthenumberofblocks:");
scanf("%d",&nb);
printf("Enterthenumberoffiles:");scanf("
%d",&nf);
printf("Block%d:",i);
scanf("%d",&b[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)//ifbf[j]isnotallocated
temp=b[j]-
f[i];if(temp>=
0)
if(highest<temp)
}
DEPARTMENT OF CSE, MVJCE 36 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
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]);ge
tch();
INPUTEnterthenumberofblock
s:3Enterthe numberoffiles: 2
Enterthesizeoftheblocks:-
Block1:5
Block2: 2
Block3: 7
Enterthesizeofthefiles:-File
1:1
File2:4
OUTPUT
FileNo FileSize Block No BlockSize Fragment
1 1 3 7 6
2 4 1 5 1
A) FIRSTINFIRSTOUTS
OURCECODE :
#include<stdio.h>#include<
conio.h>
int fr[3];
voidmain()
voiddisplay();
inti,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;
}
DEPARTMENT OF CSE, MVJCE 38 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
if(flag1==0)
for(i=0;i<frsize;i++)
if(fr[i]==-1)
fr[i]=page[j];flag2=1;break;
if(flag2==0)
fr[top]=page[j];
top++;
pf++;if(top>=f
rsize)top=0;
display();
printf("Numberofpagefaults:%d",pf+frsize);get
ch();
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
521
524
524
324
324
354
352
Numberofpagefaults:9
LRU
SOURCECODE:
#include<stdio.h>
#include<conio.h>
intfr[3];
voidmain()
voiddisplay();
intp[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
int
index,k,l,flag1=0,flag2=0,pf=0,frsize=3;clr
scr();
for(i=0;i<3;i++)
DEPARTMENT OF CSE, MVJCE 40 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
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)
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("\nnoofpagefaults:%d",pf+frsize);get
ch();
voiddisplay()
inti;printf("\n");for(i=0;i<3;i++)
printf("\t%d",fr[i]);
OUTPUT:
2-1-1
23-1
DEPARTMENT OF CSE, MVJCE 42 2024-2025
OPERATING SYSTEMS [MVJ22CS32]
23-1
231
251
251
254
254
354
352
352
352
Noofpage faults:7
char
dname[10],fname[10][10];
intfcnt;
}dir;
voidmain()
int i,ch;
charf[30];
clrscr();dir.fcnt
= 0;
while(1)
printf("\n\n1.CreateFile\t2.DeleteFile\t3.SearchFile \n
switch(ch)
case1:printf("\nEnterthenameofthefile--
");scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;break;
for(i=0;i<dir.fcnt;i++)
if(strcmp(f,dir.fname[i])==0)
printf("File%sisdeleted",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
if(i==dir.fcnt)
printf("File%snotfound",f);
else
dir.fcnt--
;break;
case3: printf("\nEnterthenameofthefile--");
scanf("%s",f);for(i=0;
i<dir.fcnt;i++)
if(strcmp(f,dir.fname[i])==0)
printf("File%sisfound",f);bre
ak;
if(i==dir.fcnt)
printf("File%snotfound",f);b
reak;
case4: if(dir.fcnt==0)
printf("\nDirectoryEmpty");
else
break;
OPERATING SYSTEMS [MVJ22CS32]
getch();
default:exit(0);
}
OUTPUT:
Enternameofdirectory--CSE
1. CreateFile2. DeleteFile3. SearchFile
4. DisplayFiles5.ExitEnteryourchoice–1
TheFilesare--ABC
1. CreateFile2. DeleteFile3. SearchFile
4. DisplayFiles5.ExitEnteryour choice–3
Enterthenameofthefile–
ABCFileABCnotfound
1. CreateFile2. DeleteFile3. SearchFile
4. DisplayFiles5. ExitEnteryourchoice–2
Enterthenameofthefile–
BFileBisdeleted
1. CreateFile2.DeleteFile3.SearchFile
4. DisplayFiles5.ExitEnteryourchoice–5
TWOLEVELDIRECTORY
SOURCECODE :
#include<stdio.h>
struct
{
char
dname[10],fname[10][10];
intfcnt;
}dir[10];
voidmain()
{
int i,ch,dcnt,k;
charf[30], d[30];
clrscr();dcnt=0;
while(1)
{
printf("\n\n1.CreateDirectory\t2.CreateFile\t3.DeleteFile");printf("\n4
.SearchFile\t\t5.Display\t6.Exit\tEnteryour choice--
");scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter name of directory --
");scanf("%s",
dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directorycreated");break;
case2:printf("\nEnternameofthedirectory—
");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Entername of the file--
");scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;printf("F
ilecreated");
}
if(i==dcnt)
printf("Directory%snotfound",d);b
reak;
case3:printf("\nEnternameofthedirectory--
");scanf("%s",d);
for(i=0;i<dcnt;i++)
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enternameofthefile--
");scanf("%s",f);for(k=0;k<dir[i].fcnt;
k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File%sisdeleted",f);di
r[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);got
ojmp;
}
}
printf("File%snotfound",f);gotojmp;
}
}
printf("Directory%snotfound",d);j
mp:break;
case4:printf("\nEnternameofthedirectory--
");scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enterthenameofthefile--
");scanf("%s",f);for(k=0;k<dir[i].fcnt;
k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File%s is found",f);gotojmp1;
}
}
printf("File%snotfound",f);gotojmp1;
}
}printf("Directory%snotfound",d);jmp1:break;case 5:if(dcnt==0)
printf("\nNoDirectory's");
else
{
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);for(k=0;k<dir[i].fcnt;k++
)printf("\t%s",dir[i].fname[k]);
}
}
break;
default:exit(0);
}
}
getch();
}
Page 45
OPERATING SYSTEMS [MVJ22CS43]
OUTPUT
1.CreateDirectory2.CreateFile3.DeleteFile
4.SearchFile5.Display6.E
xitEnteryourchoice--1
Enternameofdirectory--DIR1Directorycreated
1.CreateDirectory2.CreateFile3.DeleteFile
4. Search File 5. Display 6. Exit Enter your
choice -- 1Enternameof directory--
DIR2Directorycreated
1.CreateDirectory2.CreateFile3.DeleteFile
4. Search File 5. Display 6. Exit Enter your
choice -- 2Enternameofthedirectory–DIR1
Enter name of the file
-- A1Filecreated
1.CreateDirectory2.CreateFile3.DeleteFile
4.SearchFile5.Display6.E
xitEnteryourchoice--2
Enternameofthedirectory–DIR1
SOURCECODE :
#include<st
dio.h>main
()
{
intf[50],p,i,j,k,a,st,le
n,n,c;clrscr();
for(i=0;i<50;i++)f[i]=0;
printf("Enterhowmanyblocksthatarealread
yallocated");scanf("%d",&p);
printf("\nEntertheblocksno.sthatarealreadyallocated
");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]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
getch( );
}
OUTPUT:
Enterhowmanyblocksthatarealreadyallocated3Entertheblocksno.sthatare
alreadyallocated47Enterthestartingindexblock& length379
3->1
4-
>1fileisalreadyallocat
ed5->1
6->1
7-
>1fileisalreadyallocat
ed8->1
9->1file is already
allocated10->1
11->1
12->1
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("\nAverageheadermovements:%f",(float)su
m/n);getch();
}
INPUT
Enterno.oftracks:9
Entertrackposition:55 58 60 70 18 90 150 160184
OUTPUT
Trackstraversed Difference betweentracks
150 50
160 10
184 24
90 94
70 20
60 10
58 2
55 3
18 37
Average headermovements:27.77