0% found this document useful (0 votes)
9 views72 pages

1 (2 - 15) Merged Merged

The document outlines the vision and mission of Velammal Institute of Technology and its Department of Information Technology, emphasizing quality education, teamwork, and innovation to meet industry needs. It details the Program Educational Objectives (PEOs) and Program Specific Outcomes (PSOs) aimed at developing technical competence, leadership, and lifelong learning among students. Additionally, it includes a list of practical exercises for an Operating Systems laboratory course, focusing on UNIX commands and system calls.

Uploaded by

lathi786sree
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)
9 views72 pages

1 (2 - 15) Merged Merged

The document outlines the vision and mission of Velammal Institute of Technology and its Department of Information Technology, emphasizing quality education, teamwork, and innovation to meet industry needs. It details the Program Educational Objectives (PEOs) and Program Specific Outcomes (PSOs) aimed at developing technical competence, leadership, and lifelong learning among students. Additionally, it includes a list of practical exercises for an Operating Systems laboratory course, focusing on UNIX commands and system calls.

Uploaded by

lathi786sree
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/ 72

Vision and Mission of the College

Vision of Institute
Velammal Institute of Technology is committed to be a leader in innovative work force
development and a world class learning venue for the ever-changing needs of business and Industry.

Mission of Institute
 To promote quality education & technical skills to meet the industry requirements.
 To incorporate Team work, Leadership skills & Lifelong learning.
 To facilitate Career development & Higher education assistance
 To encourage innovative ideas for Research & Development and Entrepreneurship for
societal needs.
 To inculcate Ethical responsibility & Human values

Department of Information Technology


Vision and Mission of Department of Information Technology

Vision of the Department


To be a center of excellence in the field of Information Technology to solve complex industrial and
societal needs.

Mission of the Department

 Imparting strong knowledge to students in recent technologies by organizing various technical


events.
 Providing platform for the students to encourage creativity, team work, leadership quality and
social responsibility
 Developing the employability and entrepreneurial skills of the students by conducting industry
collaborated training.
 Inculcating the importance of research and higher education through awareness programs.
Department of Information Technology
Programme Educational Objectives (PEOs) &Program Specific Outcomes
Programme Educational Objectives

PEO I:

Demonstrate technical competence with analytical and critical thinking to understand


and meet the diversified requirements of industry, academia and research.

PEO II:
Exhibit technical leadership, team skills and entrepreneurship skills to provide business solutions to
real world problems.

PEO III:
Work in multi-disciplinary industries with social and environmental responsibility work ethics and
adaptability to address complex engineering and social problems

PEO IV:
Pursue lifelong learning, use cutting edge technologies and involve in applied research to design
optimal solutions.

Program Specific Outcomes

PSO1:
Have proficiency in programming skills to design, develop and apply appropriate techniques, to
solve complex engineering problems

PSO2:
Have knowledge to build, automate and manage business solutions using cutting edge technologies.

PSO3:
Have excitement towards research in applied computer technologies.
Program Outcomes
Program Outcomes
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
PO1 fundamentals, and an engineering specialization to the solution of complex engineering
problems.
Problem analysis: Identify, formulate, review research literature, and analyze complex
PO2 engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
PO3 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
PO4 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
PO5 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
PO6 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
PO7 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
PO8 norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or
PO9 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
PO10 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
PO11 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
PO12 in independent and life-long learning in the broadest context of technological change.

Staff Incharge HoD


CS3461 INTRODUCTION TO OPERATING SYSTEM LABORATORY

LIST OF PRACTICAL EXERCISES

1.a. Introduction Of Unix Commands


1.b. Basic Unix Commands
2. OS fork,exec,getpid,exit,wait,close,stat,readdir
3. C program to simulate UNIX commands like cp,ls,grep
4. Simple Shell Programs
5.a. Develop a CPU Sheduling Algorithms for Priority
5.b. Develop a CPU Sheduling Algorithms for Round Robin Scheduling
5.c. Develop a CPU Sheduling Algorithms for FCFS
5.d. Develop a CPU Sheduling Algorithms for SJF scheduling
6. Develop a producer consumer problem using Semaphores
7. IPC using shared Memory
8. Bankers algorithm for Deadlock Avoidace
9. Develope a algorithm for Deadlock Detection
10. Threadining and Synchronization Application
11.a. Memory Allocation Methods for Fixed Parition for First Fit
11.b. Memory Allocation Methods for Fixed Parition for Worst Fit
11.c. Memory Allocation Methods for Fixed Parition for Best Fit
12. C program for Paging Techniques of Memory Management
13.a. Paging Replacement Algorithms for FIFO
13.b. Paging Replacement Algorithms for LRU
13.c. Paging Replacement Algorithms for LFU
14.a. File Organization Techniques for Single Level Directory
14.b. File Organization Techniques for Two Level Directory
15.a. File Allocation Strategies for Sequential
15.b. File Allocation Strategies for Linked
15.c. File Allocation Strategies for Indexed
CONTENTS
Expt Page Lecture’s
Date Title of the Experiment Remarks
No. No. Initial
1.a 26-02-25 Introduction Of Unix Commands 3
1.b 26-02-25 Basic Unix Commands 5
2 05-03-25 OS fork,exec,getpid,exit,wait,close,stat,readdir 7
C program to simulate UNIX commands like
3 12-03-25 8
cp,ls,grep
4 19-03-25 Simple Shell Programs 10
Develop a CPU Sheduling Algorithms for
5.a 02-04-25 13
Priority
Develop a CPU Sheduling Algorithms for
5.b 2‑04‑25 14
Round Robin Scheduling
Develop a CPU Sheduling Algorithms for
5.c 02-04-25 17
FCFS
Develop a CPU Sheduling Algorithms for SJF
5.d 02-04-25 20
scheduling
Develop a producer consumer problem using
6 09-04-25 24
Semaphores
7 16-04-25 IPC using shared Memory 26
8 23-04-25 Bankers algorithm for Deadlock Avoidace 28
9 28-04-25 Develope a algorithm for Deadlock Detection 30
10 30-4-25 Threadining and Synchronization Application 34
Memory Allocation Methods for Fixed Parition
11.a 02-05-25 37
for First Fit
Memory Allocation Methods for Fixed Parition
11.b 02-05-25 38
for Worst Fit
Memory Allocation Methods for Fixed Parition
11.c 02-05-25 39
for Best Fit
C program for Paging Techniques of Memory
12 05-05-25 41
Management
13.a 07-05-25 Paging Replacement Algorithms for FIFO 43
13.b 07-05-25 Paging Replacement Algorithms for LRU 47
13.c 07-05-25 Paging Replacement Algorithms for LFU 50
File Organization Techniques for Single Level
14.a 10-05-25 55
Directory
File Organization Techniques for Two Level
14.b 10-05-25 60
Directory
15.a 12-05-25 File Allocation Strategies for Sequential 65
15.b 12-05-25 File Allocation Strategies for Linked 69
15.c 14-05-25 File Allocation Strategies for Indexed 70
BASICSOFUNIXCOMMANDS
Ex.no. 1.a
Date:26-02-25
AIM:
To study about the basics of UNIX

UNIX:
Itisa multi-user operating system. Developed atAT&TBellIndustries, USAin 1969.

Ken Thomson along with Dennis Ritchie developed it from MULTICS


(MultiplexedInformation and ComputingService)OS.
By1980,UNIXhadbeencompletelyrewrittenusingClanguage.

LINUX:
It is similar to UNIX, which is created by Linus Torualds. All UNIX
commands worksin Linux. Linux is a open source software. The main feature of
Linux is coexisting with otherOSsuchaswindowsandUNIX.

STRUCTUREOFALINUXSYSTEM:
It consists of three parts.

a) UNIXkernel
b) Shells
c) ToolsandApplications

UNIXKERNEL:
Kernelis thecoreof theUNIX OS.Itcontrols
alltasks,scheduleallProcessesandcarries out all thefunctions ofOS.

Decideswhenoneprogramstopsandanother starts.

SHELL:
Shellis thecommand interpreterin the UNIX OS.It acceptscommandfrom
the userand analyses andinterprets them
BASICS OF UNIX COMMANDS
Ex.no. 1.b
Date: 26-02-25

AIM:
To study of Basic UNIX Commands and various UNIX editors such as vi,ed,ex and EMACS.
CONTENT:
Note:Syn->Syntax
a) date
–used to check the date and
timeSyn:$date
Format Purpose Example Result
+%m Todisplayonlymonth $date+%m 06
+%h Todisplaymonthname $date+%h June
+%d Todisplaydayofmonth $date+%d O1
+%y Todisplaylasttwodigitsofyears $date+%y 09
+%H Todisplayhours $date+%H 10
+%M Todisplayminutes $date+%M 45
+%S Todisplayseconds $date+%S 55

b) cal
–used to display the
calendarSyn:$cal2 2009

c)echo
–used toprintthe message on thescreen.
Syn:$echo“text”

d) ls
–usedtolistthefiles.Yourfilesarekeptinadirectory.
Syn:$lsls–s
All files (include files with prefix)ls–
l Lodetai (provide file statistics)ls–
tOrder bycreation time
ls–uSortbyaccesstime(or showwhenlastaccessedtogetherwith–l)ls–sOrder
bysize
ls–rReverseorder
ls–fMark directories with /,executable with* , symbolic links with @, local sockets with
=,namedpipes(FIFOs)with
ls–sShowfilesize
ls–h“HumanReadable”, showfile sizeinKiloBytes &MegaBytes(h can beusedtogetherwith–lor)

FILEMANIPULATIONCOMMANDS
cat–this create, viewand concatenatefiles.
Creation:
Syn:$cat>filename

Viewing:
Syn:$catfilename
Addtext to anexisting file:
Syn:$cat>>filename

Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (nooverwritingoffile3)

a) grep–usedto search aparticularword orpattern related to thatwordfrom


thefile.Syn:$grep search wordfilename
Eg:$grepanustudent

b) rm–deletes
afilefromthefilesystemSyn:$rmfilename

c) touch–usedtocreatea blank file.


Syn:$touchfilenames

d) cp–copies the files or


directoriesSyn:$cpsource file
destination fileEg:$cp student stud

e) mv–to rename
thefileordirectorysyn:$mvold
filenewfile
Eg:$mv–istudent student list(-iprompt when overwrite)

f) cut–it cutsor pickupagivennumber ofcharacter or fields


ofthefile.Syn:$cut<option><filename>
Eg:$cut–cfilename
$cut–c1-10emp
$cut–f3,6emp
$cut –f3-6tail–displays last 10 lines of the fileSyn:$tail filename
Todisplaythebottomtwo lines;
Syn:$tail -2student
OUTPUT:
The outputs like y,n, m command line will executed.

RESULT:
Thus the program for the Basic Unix Commands executed successfully.
Os Fork,Exec,Getpid,Exit,Wait,Close,Stat,Readdir
Ex.no. 2
Date: 5-3-25
AIM:
To write C Programs using the following system calls of UNIX operating system fork,exec,getpid,
exit, wait,close, stat, opendir,readdir.

1. PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEMS (OPENDIR,RE


ADDIR,CLOSEDIR)

ALGORITHM:

STEP 1: Start the


program.STEP2:Createstru
ctdirent.
STEP3:declarethevariablebuffandpointerdptr.ST
EP4:Get thedirectoryname.
STEP5:Openthedirectory.
STEP6:Readthecontents
indirectoryandprintit.STEP7:Close thedirectory.

PROGRAM:
#include<stdio.h>#inclu
de<dirent.h>structdirent
*dptr;

intmain(intargc,char*argv[])

{
char
buff[100];DIR*d
irp;
printf(“\n\nENTERDIRECTORYNAME”);scanf(“
%s”, buff);if((dirp=opendir(buff))==NULL)

{
printf(“Thegivendirectorydoesnotexist”);exit(1);

while(dptr=readdir(dirp))

{
printf(“%s\n”,dptr->d_name);

closedir(dirp);
}

OUTPUT:
ENTER DIRECTORY NAME: test
file1.txt
file2.txt
subdir1

2. PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEM(fork,getpid,exi


t)

ALGORITHM:
STEP1:Start theprogram.
STEP 2: Declare the variables
pid,pid1,pid2.STEP3:
Callfork()systemcalltocreateprocess.STEP4:If
pid==-1, exit.
STEP5: Ifpid!=-
1,gettheprocessidusinggetpid().STEP6: Print
theprocess id.
STEP7:Stoptheprogram

PROGRAM:
#include<stdio.h>#inclu
de<unistd.h>main(){
int
pid,pid1,pid2;=fork
();if(pid==-1){

printf(“ERRORINPROCESSCREATION\n”);

exit(1);}
if(pid!=0)
{

pid1=getpid();

printf(“\ntheparentprocess IDis%d\n”,pid1);
}else
{pid2=getpid();

printf(“\nthechildprocessIDis%d\n”,pid2);
}}

OUTPUT:

The parent process ID is 1234


The child process ID is 1235

RESULT;
Thus the program for the Os Fork,Exec,Getpid,Exit,Wait,Close,Stat,Readdir
Executed successfully .
C programs tos imulate unix commands likecp,ls,grep.
Ex.no. 3
Date: 12-03-25

AIM:
To write C programs to simulate UNIX commands like cp,ls,grep.

1. Program for simulation of cpu unix commands

ALGORITHM:
STEP1:Starttheprogram
STEP2:Declarethevariablesch,*fp,sc
=0STEP3: Open thefilein readmode
STEP4:Get thecharacter
STEP5:Ifch==““thenincrement scvalue
byoneSTEP6: Print no of spaces
STEP7:Close thefile

PROGRAM:
#include<fcntl.h>#in
clude<unistd.h>#incl
ude<stdio.h>main(int
argc,char*argv[])
%d",sc);printf("\n");
fclose(fp);
}
}
Output:
./a.out example.txt

2.PROGRAM FOR SIMULATION OF LSUNIX COMMANDS

ALGORTIHM:

STEP1:Starttheprogram
STEP2:OpenthedirectorywithdirectoryobjectdpSTEP3
:Readthedirectorycontent andprintit.STEP4:Closethedirectory.
PROGRAM:

1
#include<stdio.h>#inclu
de<dirent.h>main(intarg
c,char**argv)

DIR *dp;
struct dirent
*link;dp=opendir
(argv[1]);
printf(“\ncontentsofthedirectory%sare\n”,argv[1]);while((link=readdir(dp))!=0)
printf(“%s”,link-
>d_name);closedir(dp);

OUTPUT:

./a.out example_directory
3.PROGRAMFOR SIMULATIONOFGREPUNIXCOMMANDSALGORITHM
STEP1:Starttheprogram
STEP2:Declarethevariables fline[max],count=0,occurrences=0andpointers*fp,

*newline.

STEP3: Openthefilein readmode.

STEP4:Inwhileloopcheckfgets(fline,max,fp)!=NULl
STEP5:Incrementcountvalue.

STEP6:Checknewline=strchr(fline,„\n‟)
STEP7:printthecount,flinevalueandincrementtheoccurrencevalue.STEP8:Stoptheprogr
am

PROGRAM:

#include<stdio.h>#
include<string.h>#
define max
1024void usage()
{

2
printf(“usage:\t./a.outfilenameword \n“);

intmain(intargc,char*argv[])

{
FILE*fp;
charfline[max];
char

usage();exit(1);

}if(!(fp=fopen(argv[1],”r”)))

{
printf(“grep:couldnotopenfile:%s\n”,argv[1]);exit(1
);
}while(fgets(fline,max,fp)!=NULL)

{
count++;if(newline=strchr(fl
ine,„\n‟))
*newline=‟\0‟;if(strstr(fline,arg
v[2])!=NULL)
{
printf(“%s:%d%s\n”,argv[1],count,fline);occurrences++;

}}

OUTPUT:
./a.out test.txt example

RESULT:
Thus the program for the C program to simulate UNIX commands like cp,ls,grep executed
successfully.

3
Simple Shell Programs
Ex.no. 4
Date: 19-03-25
AIM:
To write simple shell programs by using conditional ,branching and looping statements.

1. ALGORITHM:

SEPT 1: Start the


program.STEP2:Read
thevalueofn.
STEP3:Calculate„r=expr$n%2‟.
STEP 4: If the value of r equals 0 then print the number is
evenSTEP5:If thevalueofr notequal to0then printthenumber
isodd.

PROGRAM:

echo"EntertheNu
mber"readn
r=`expr$
n%2`if [
$r -eq 0
]then
echo"$nisEvennum
ber"else
echo"$nisOddnum
ber"fi
OUTPUT
Enter : echo
Rnststs
Echo

2.WriteaShellprogramtocheckthegivenyearisleapyearornot

ALGORITHM:
SEPT 1: Start the
program.STEP2:Readthe
valueofyear.
STEP3:Calculate„b=expr$y%4‟.
STEP4: Ifthevalueofb equals0thenprinttheyearisaleapyear

4
STEP5: Ifthevalueofrnotequalto0thenprintthe yearisnotaleapyear
PROGRAM:

echo"Enterthe
year"ready
b=`expr
$y %
4`if[$b -
eq 0
]then
echo"$yisaleap
year"else
echo"$yisnotaleapy
ear"fi
3. WriteaShellprogramtofindthefactorialofa

numberALGORITHM:

SEPT1:Starttheprogram.
STEP 2: Read the value
of
STEP3:Calculate„i=expr$
n-1‟.
STEP4:Ifthevalueofiisgreaterthan1thencalculate„n=expr$n\*$i‟and„i=expr$i–1‟STEP5:
Print thefactorialof thegiven number.

PROGRAM:

echo"Ent
eraNumb
er"readn
$i`i=`exp
r$i-
1`done
OUTPUT:
Echo:
File select kdfjkdj

RESULT:

Thus the program for the simple shell programs executed succrssfully.

5
Develop a Cpu Scheduling Algorithms Priority
Ex.No :5.a.
Date :02-04-25
AIM:
To write a C program for implementation of Priority scheduling algorithms.

ALGORITHM:
Step1:Inside the structure declare the variables.
Step2:Declare the variable i,j as integer,to twtime and to tttime is equal to zero.
step3:Getthevalueof„n‟assignpandallocatethememory.
Step4:Insidetheforloopgetthevalueofbursttimeandpriority.
Step 5:Assign wtimeaszero .
Step6:Check p[i].priisgreaterthan p[j].pri.
Step7:Calculatethetotalofbursttimeandwaitingtimeandassignasturnaroundtime.St
ep8: Stop theprogram.

PROGRAM:
#include<stdio.h
>#include<stdio.
h>#include<stdli
b.h>
typedefstruct
{
;;
intwtime;
}sp;
intmain()
{
int i,j,n;
inttbm=0,totwtime=0,totttime=
0;sp *p,t;
printf("\nPRIORITYSCHEDULING.\n");
printf("\nenterthenoof process. \n");
scanf("%d",&n);p=(sp*)
malloc(sizeof(sp));
printf("enterthebursttimeandpriority:\n");f
or(i=0;i<n;i++)
{
printf("process%d:”,i+1);scanf("%d
%d",&p[i].btime,&p[i].pri);
p[i].pno=i+1;
for(i=0;i
<n-
1;i++)for(j=i+1;j
<n;j++)
{

6
if(p[i].pri>p[j].pri)
;
}
}
printf("\n process\tbursttime\twaiting time\tturnaround
time\n");for(i=0;i<n;i++)
{
totwtime+=p[i].wtime=tbm;tbm+=p[
i].btime;printf("\n%d\t\t%d",p[i].pno,
p[i].btime);
printf("\t\t%d\t\t%d",p[i].wtime,p[i].wtime+p[i].btime);
}
totttime=tbm+totwtime;
printf("\ntotalwaitingtime:%d",totwtime);
printf("\naveragewaitingtime:%f",(float)totwtime/
n);printf("\n total turnaround
time:%d",totttime);printf("\navgturnaroundtime:%
f",(float)totttime/n);
}

OUTPUT:
PRIORITY SCHEDULING.
Enter the number of processes: 3
Enter the burst time and priority for each process:
Process 1: 5 2
Process 2: 3 1
Process 3: 4 3
Process Burst Time Waiting Time Turnaround Time
2 3 0 3
1 5 3 8
3 4 8 12
Total waiting time: 11
Average waiting time: 3.67
Total turnaround time: 23
Average turnaround time: 7.67

RESULT :
Thus the program for the cpu scheduling algorithms priority executed
successfully.

7
Develop a Cpu Scheduling Algorithms Round Robin Scheduling

Ex.No: 5.b
Date: 02-04-25
AIM:

To write a C program for implementation of Round Robin scheduling algorithms.

ALGORITHM:

Step1:Inside the structure declare the variables.


Step2:Declare the variable i,j as integer,to twtime and tott time is equal to zero.
step3:Get the value of "n‟ assign panda llocate the memory.
Step4:Insidethefor loopget thevalueofburst timeand priorityand readthe
timequantum.Step5:Assign wtimeaszero.
Step6:Check p[i].priisgreaterthan p[j].pri.
Step7:Calculatethetotalofbursttimeandwaitingtimeandassignasturnaroundtime.Step8:
Stop theprogram.

PROGRAM:

#include<stdio.
h>#include<stdl
ib.h> structrr
{
intpno,btime,sbtime,wtime,lst;
}p[10];
intmain()
{
int pp=-
1,ts,flag,count,ptm=0,i,n,twt=0,totttime=0;printf
("\nroundrobinscheduling ........... ");
printf("enternoofprocesses:")
;scanf("%d",&n);
printf("enterthetimeslice:")
;scanf("%d",&ts);printf("e
nter the burst
time");for(i=0;i<n;i++)
{
printf("\nprocess%d\t",i+
1);scanf("%d",&p[i].btim
e);
p[i].wtime=p[i].lst=0;p[i].p

8
printf("scheduling \n");
do
{
flag=0;for(i=
0;i<n;i++)
{
count=p[i].bti
me;if(count>0)
{
flag=-
1;count=(count>=ts)?ts:count;
printf("\n process
%d",p[i].pno);printf("from%d
",ptm);ptm+=count;printf("to
%d",ptm);
p[i].btime-
=count;if(pp!=i)
{
pp=i;
p[i].wtime+=ptm-p[i].lst-
count;p[i].lst=ptm;
}
}

OUTPUT:
Round Robin Scheduling
Enter the number of processes: 3
Enter the time slice: 2
Enter the burst time:
Process 1: 5
Process 2: 3
Process 3: 4

Process Waiting Time


1 5
2 0
3 2
Total Waiting Time: 7
Average Waiting Time: 2.33
Total Turnaround Time: 10
Average Turnaround Time: 3.33

RESULT:
Thus the program for the Cpu Scheduling Algorithms Round Robin Scheduling
executed successfully.

9
Develop A Cpu Scheduling Algorithms Fcfs
Ex.No: 5.c.
Date: 02-04-25
AIM:
To write a C program for implementation of FCFS and SJF scheduling algorithms.
ALGORITHM:

Step1:Insidethestructuredeclarethevariables.
Step2:Declarethevariablei,jasinteger,totwtimeandtotttimeisequaltozer
o.Step3:Getthevalueof„n‟assignpidasIandgetthevalueofp[i].btime.
Step 4: Assign p[0] wtime as zero and tot time as btime and inside the loop calculate
wait timeandturnaroundtime.
Step5: Calculate total wait time and total turnaround time bydividingbytotal
numberofprocess.
Step 6: Print total wait time and total
turnaround time.Step7: Stop theprogram.

PROGRAM:

#include<std
io.h>#includ
e<stdlib.h>
structfcfs
{
intpi
d;int
btim
e;int
wti
me;i
nttti
me;
int i,n;
int
towtwtime=0,totttime=0;p
rintf("\n fcfs
scheduling...\n");printf("e
nterthenoofprocess");scan
f("%d",&n);for(i=0;i<n;i+
+)
{
p[i].pid=1;
printf("\nbursttimeofthe
process”);scanf("%d",&

10
p[i].btime);

p[0].wtime=0;p[0].t
time=p[0].btime;tott
time+=p[i].ttime;for
(i=0;i<n;i++)
{
p[i].wtime=p[i-1].wtime+p[i-1].btim
p[i].ttime=p[i].wtime+p[i].btime;tott
time+=p[i].ttime;towtwtime+=p[i].
wtime;
}
for(i=0;i<n;i++)
{{
printf("\n waiting time for
process”);printf("\nturnaroundtimefor
process”);printf("\n");
}}
printf("\ntotalwaitingtime:%d",totwtime);printf("\na
veragewaitingtime:%f",(float)totwtime/n);printf("\nt
otal turnaround time:%d",totttime);
printf("\naverageturnaroundtime::%f",(float)totttime/n);
}

OUTPUT:

FCFS Scheduling
Enter the number of processes: 3
Enter burst time of process 1: 5
Enter burst time of process 2: 3
Enter burst time of process 3: 4

Process Waiting Time Turnaround Time


1 0 5
2 5 8
3 8 12

Total Waiting Time: 13


Average Waiting Time: 4.33
Total Turnaround Time: 25
Average Turnaround Time: 8.33

RESULT:
Thus the program for the Cpu Scheduling Algorithms Fcfs executed successfully.

11
Develop a Cpu Scheduling Algorithms Sjf Scheduling

Ex.No: 5.d
Date: 02-04-25
AIM:
To write a C program for implementation of SJF scheduling algorithms.

ALGORITHM:
Step1:Insidethestructuredeclarethevariables.
Step2:Declarethevariablei,jasinteger,totwtimeandtotttimeisequaltozero.St
ep3:Getthevalueof„n‟assignpidasIandgetthevalueofp[i].btime.
Step 4: Assign p[0] wtime as zero and tot time as btime and inside the loop calculate
wait timeandturnaroundtime.
Step 5: Calculate total wait time and total turnaround time by dividing by total
number ofprocess.
Step6:Printtotalwaittimeandtotalturnaroundtime
.Step7: Stop theprogram.

PROGRAM:
#include<std
io.h>#includ
e<stdlib.h>
typedefstruct
}
sp;
intmain()
{
int
i,j,n,tbm=0,towtwtime=0,tottti
mesp*p,t;
printf("\n sjf schaduling
..\n");printf("enterthenoofpr
ocessor");scanf("%d",&n);p
=(sp*)malloc(sizeof(sp));pri
ntf("\n enter the burst
time");for(i=0;i<n;i++)
{
printf("\nprocess%d\t",
i+1);scanf("%d",&p[i].
btime);p[i].pid=i+1;
p[i].wtime=0;

for(i=0;i<n;
{
if(p[i].btime>p[j].btime)
printf("\n process

12
scheduling\n");printf("\n
process \tburst time \t
wfor(i=0;i<n;i++)
{
towtwtime+=p[i].wtime=tbm;tb
m+=p[i].btime;printf("\n%d\t\t%
d",p[i].pid,p[i].btprintf("\t\t%d\t\
t%d",p[i].wtime,p[i
}
totttime=tbm+towtwtime;
printf("\ntotalwaitingtime:%d",totwtime);printf("
\naveragewaitingtime:%f",(float)totwtime/n);prin
tf("\ntotal turnaround time :%d",totttime);
printf("\naverageturnaroundtime::%f",(float)totttime/n);
}

OUTPUT:
SJF Scheduling
Enter the number of processes: 3

Enter the burst time:


Process 1: 5
Process 2: 3
Process 3: 4

Process Scheduling
Process Burst Time Waiting Time
2 3 0
3 4 3
1 5 7

Total Waiting Time: 10


Average Waiting Time: 3.33
Total Turnaround Time: 12
Average Turnaround Time: 4.00

RESULT:

Thus the progem for the Cpu Scheduling Algorithms Sjf Scheduling executed
successfully.

13
Develop a Producer Consumer Problemusing Semaphores

Ex.No : 6
Date : 09-04-25
AIM:
To write a C-program to implement the producer–consumer problem using
semaphores.
ALGORITHM:
Step1:Starttheprogram.
Step2:Declaretherequiredvariables.
Step3:Initializethebuffersizeand getmaximumitemyouwanttoproduce.
Step4:Gettheoption,whichyouwanttodoeitherproducer,
Step5:Ifyouselecttheproducer,
Step6:Ifyouselecttheconsumer,checkthebuffersizeifitisemptythe
Step7:Ifyouselectexitcomeoutoftheprogram.
Step8: Stop theprogram.

PROGRAM:
#include<stdio.h>
int
mutex=1,full=0,empty=3,x
=0;main()
{
int n;
void
producer();
void
consumer()
;intwait(int
);
int
signal(int);printf("\n1.PRODUCER\n2.CONSUME
R\n3.EXIT\n");while(1){
printf("\nENTER YOUR
CHOICE\n");scanf("%d",&n);
switch(n)
{case1:
if((mutex==1)&&(empty!=0))pr
oducer();
s)
{return(-
-s);}
int
signal(int

14
s)
{return(++
s);
}voidprodu
cer(){
mutex=wait(m
utex);full=sign
al(full);empty
=wait(empty);
x++;
printf("\nproducer produces the
item%d",x);mutex=signal(mutex);}
void consumer()
{mutex=wait(mutex);full
=wait(full);empty=signal(
empty);
printf("\nconsumerconsumesitem%d
",x);x--;
mutex=signal(mutex);}

break\
OUTPUT:

1. PRODUCER
2. CONSUMER
3. EXIT
ENTER YOUR CHOICE: 1
Producer produces the item 1
ENTER YOUR CHOICE: 2
Consumer consumes item 1
ENTER YOUR CHOICE: 2
BUFFER IS EMPTY
ENTER YOUR CHOICE: 1

Producer produces the item 2


ENTER YOUR CHOICE: 1
BUFFER IS FULL
ENTER YOUR CHOICE: 3
Producer produces the item 1

RESULT:
Thus the program for the producer consumer problemusing semaphores executed
successfully.

15
IPC Using Shared Memory
Ex.No: 7
Date :16-04-25
AIM:
To write a c program to implement IPC using shared memory.

ALGORITHM:
Step1:Starttheprocess
Step 2: Declare the segment
sizeStep3:Createthesharedmem
ory
Step 4: Read the data from the shared
memoryStep 5: Write the data to the shared
memoryStep6: Edit the data
Step7:Stop theprocess

PROGRAM:

#include<stdio.h>#i
nclude<stdlib.h>#in
clude<unistd.h>#in
clude<string.h>#inc
lude<sys/ipc.h>#inc
lude<sys/shm.h>#in
clude<sys/types.h>
#defineSEGSIZE10
0
intmain(intargc,char*argv[])
{
int
shmid,cntr;
key_t
key;char*se
gptr;
charbuff[]="poooda ";
key=ftok(".",'s');
if((shmid=shmget(key,SEGSIZE,IPC_CREAT|IPC_EXCL|0666))==-1)
{
if((shmid=shmget(key,SEGSIZE,0))==-1)
{
perror("shmget
");exit(1);
}

16
}
else

{printf("Creating a new shared memory seg


\n");printf("SHMID:%d",shmid);
}
system("ipcs –
m");if((segptr=(char*)shmat(shmid,0,0))==(ch
ar*)-1)
{
perror("shmat
");exit(1);
}
printf("Writingdatatosharedmemory…\n");
strcpy(segptr,buff);
printf("DONE\n");
printf("Reading data from shared
memory…\n");printf("DATA:-
%s\n",segptr);printf("DONE\n");
printf("Removingshared
memorySegment…\n");if(shmctl(shmid,IPC_R
MID,0)== -1)
printf("Can‟tRemoveSharedmemorySegment…\n");
else
printf("RemovedSuccessfully");
}
OUTPUT:
Creating a new shared memory segment
SHMID: 123456789
...
Writing data to shared memory...
DONE
Reading data from shared memory...
DATA: poooda
DONE
Removing shared memory Segment...
Removed Successfully

RESULT:
Thus the program for the IPC Using Shared Memory executed successfully.

17
Bankers Algorithmfor Deadlock Avoidance
Ex.No: 8
Date: 22-04-24
AIM:
To write a C program to implement banker‟s algorithm for deadlock avoidance.
ALGORITHM:
Step-1:Starttheprogram.
Step-2:Declarethe memoryfortheprocess.
Step-3: Read the number of process, resources, allocation matrix and available
matrix.Step-4:Compareeachandeveryprocessusingthebanker‟salgorithm.
Step-5:Iftheprocess isinsafestatethen itisa nota deadlockprocessotherwise
itisadeadlockprocess
Step-
6:producetheresultofstateofprocessStep-
7:Stop theprogram
PROGRAM:

#include<stdio.h
>#include<conio
.h>int
max[100][100];i
nt
alloc[100][100];i
nt
need[100][100];i
ntavail[100];
int n,r;
void
input();vo
id
show();vo
id
cal();intm
ain()
{
int i,j;
printf("********** Baner's Algo
************\n");input();
show();
cal();
getch(
);retur
n0;
}
void input()
{

18
int i,j;
printf("Entertheno ofProcesses\t");

scanf("%d",&n);
printf("Enterthenoofresourcesinstances\t");
scanf("%d",&r);
printf("EntertheMaxMatrix\n")
;for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}}
printf("Enter the Allocation
Matrix\n");for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}}
printf("Enter the available
Resources\n");for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}}
voidshow()
{
int i,j;
printf("Process\tAllocation\t
Max\tAvailable\t");for(i=0;i<n;i++)
{
printf("\nP%d\t",i+
1);for(j=0;j<r;j++)
{
printf("%d",alloc[i][j]);
}
printf("\t");fo
r(j=0;j<r;j++)
{
printf("%d",max[i][j]);
}
printf("\t
");if(i==
0)
{
for(j=0;j<r;j++)pri
ntf("%d",avail[j]);}
}}

19
OUTPUT:
Number of processes: 5
Number of resource instances: 3
Max Matrix:
555
463
223
564
632
Allocation Matrix:
122
011
135
063
001
Available Resources:
111
Enter the number of processes: 5
Enter the number of resource instances: 3
Enter the Max Matrix:
555
463
223
564
632
Enter the Allocation Matrix:
122
011
111
Process sequence to avoid deadlock: P1 -> P3 -> P5 -> P4 -> P2
The system is in a safe state.

RESULT:
Thus the program for the bankers algorithmfor deadlock avoidance executed successfully.

20
Develop A Algorithm for deadlock detection

Ex.No: 9
Date: 28-04-25
AIM:
TowriteaCprogramtoimplementalgorithmfordeadlockdetection.
ALGORITHM:
Step-1:Starttheprogram.
Step-2:Declarethe memoryfortheprocess.
Step-3: Read the number of process, resources, allocation matrix and available
matrix.Step-4:Compareeachandeveryprocessusingthebanker‟salgorithm.
Step-5:Iftheprocess isinsafestatethenit isanot adeadlockprocess otherwiseitis
6:producetheresultofstateofprocessStep-
7:Stop theprogram
PROGRAM:

#include<stdio.h
>#include<conio
.h>int
max[100][100];i
nt
alloc[100][100];i
nt
need[100][100];i
ntavail[100];
int n,r;
void
input();vo
id
show();vo
id
cal();intm
ain()
{
int i,j;
printf("********** Deadlock Detection Algo
************\n");input();
show();
cal();
getch(
);retur
n0;
}
void input()
{int i,j;

21
printf("Enterthenoofresourceinstances\t");scanf("%d",&r);
printf("EntertheMaxMatrix\n")
;for(i=0;i<n;i++)
{for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}}
printf("Enter the Allocation
Matrix\n");for(i=0;i<n;i++)
{for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}}
printf("Enter the available
Resources\n");for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}}
voidshow()
{
int i,j;
printf("Process\tAllocation\tMax\tAvailable\t")
;for(i=0;i<n;i++)
{
printf("\nP%d\t",i+
1);for(j=0;j<r;j++)
{
printf("%d",alloc[i][j]);
}
printf("\t");fo
r(j=0;j<r;j++)
{printf("%d",max[i][j]);
}
printf("\t
");if(i==
0)
{
for(j=0;j<r;j++)pri
ntf("%d",avail[j]);
}}}
voidcal()
{intfinish[100],temp,need[100][100],flag=1,k,c1=
0;int dead[100];
int
safe[100];i
nt i,j;

22
for(i=0;i<n;i++)
{finish[i]=0;
}
//findneedmatri
xfor(i=0;i<n;i+
+)
{for(j=0;j<r;j++)
{
need[i][j]=max[i][j]-alloc[i][j];
}}
while(flag)
{flag=0;for(i
=0;i<n;i++)
{int
c=0;for(j=0;j
<r;j++)
{if((finish[i]==0)&&(need[i][j]<=avail[j]))
{c++;
if(c==r)
{
for(k=0;k<r;k++)
{avail[k]+=alloc[i][
j];finish[i]=1;
flag=1;
}//printf("\nP%d",i);if(finish[
i]==1)
{i=n;
}}}}
}}j=0
;
flag=0;for(i=
0;i<n;i++)
{
if(finish[i]==0)
{dead[j]
=i;j++;
flag=1;
}}
if(flag==1)
{
printf("\n\nSystem is in Deadlock and the Deadlock process
are\n");for(i=0;i<n;i++)
{printf("P%d\t",dead[i]);
}}
else
{
printf("\nNoDeadlockOccur");}}

23
OUTPUT:

[12:31 pm, 13/5/2024] Munivel M: Enter the number of Processes: 3


Enter the number of resource instances: 4

Enter the Max Matrix:


7534
3221
9022

Enter the Allocation Matrix:


0102
200
[12:31 pm, 13/5/2024] Munivel M: **** Deadlock Detection Algorithm ****

Process Allocation Max Available


P1 0102 7534 3322
P2 2000 3221
P3 3020 9022

System is in Deadlock and the Deadlock processes are:


P1 P3

RESULT:
Thus the program for the algorithm for deadlock detection executed
successfully .

24
Threading & Synchronization Applications
Ex.No: 10
Date: 30-04-25
AIM:
Towrite a c programtoimplementThreadingandSynchronizationApplications.
ALGORITHM:
Step1:Starttheprocess
Step2:Declareprocessthread,thread-id.
Step3:Readtheprocessthreadandthreadstate.
Step4: Checkthe process threadequals to thread-
idbyusingifcondition.Step5: Check the error state ofthe thread.
Step6:Displaythecompletedthreadprocess.S
tep7: Stop theprocess
PROGRAM:

#include<stdio.h>
#include<string.h
>#include<pthrea
d.h>#include<stdl
ib.h>#include<uni
std.h>pthread_ttid
[2];
void*doSomeThing(void*arg)
{
unsigned long i =
0;pthread_tid=pthread_self
();

if(pthread_equal(id,tid[0]))
{
printf("\nFirstthreadprocessing\n");
}
else
{
printf("\nSecondthreadprocessing\n");
}

for(i=0;i<(0xFFFFFFFF);i++);
returnNULL;
}
intmain(void)
{
int i = 0;
err=pthread_create(&(tid[i]),NULL,&doSomeThing,NU

25
LL);if(err !=0)
printf("\ncan'tcreatethread:[%s]",strerror(err));
else
printf("\nThreadcreatedsuccessfully\n");

i++;
}

sleep(
5);ret
urn0;
}
OUTPUT:
[12:31 pm, 13/5/2024] Munivel M: 10
[12:32 pm, 13/5/2024] Munivel M: Thread created successfully
First thread processing
Thread created successfully
Second thread processing

RESULT:

Thus the program for the threading & synchronization applications executed successfully.

26
Memory Allocation Methods For Fixed Partition
Firstfit
Ex.No: 11.a
Date: 02-05-25

AIM:
TowriteaCprogramforimplementation
memoryallocationmethodsforfixedpartitionusingfirst fit.

ALGORITHM:
Step1:Definethemaxas25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0,
bf[max],ff[max].Step3: Get thenumberof blocks,files,sizeof the blocksusingforloop.
Step4:Inforloopcheck bf[j]!=1,ifsotemp=b[j]-f[i]
Step 5: Check highest<temp,if so assign
ff[i]=j,highest=tempStep6: Assignfrag[i]=highest,
bf[ff[i]]=1,highest=0
Step7: Repeatstep 4to step6.
Step8:Printfileno,size,blockno,sizeandfragment.St
ep9: Stop theprogram.
PROGRAM:
#include<stdio.
h>#include<con
io.h>#define
max
25voidmain()
{
intfrag[max],b[max],f[max],i,j,nb,nf,temp,highest=
0;staticint bf[max],ff[max];
clrscr();
printf("\n\tMemoryManagementScheme-
WorstFit");printf("\nEnter the number of
blocks:");scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-
\n");for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-
\n");for(i=1;i<=nf;i++)
{

27
printf("File%d:",i);
=b[j]-
f[i];if(temp>=
0)if(highest<t
emp)
frag[i]=highe
st;bf[ff[i]]=1;
highest=0;
}
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
Memory Management Scheme - First Fit
Enter the number of blocks: 4
Enter the number of files: 3
Enter the size of the blocks:
Block 1: 10
Block 2: 20
Block 3: 15
Block 4: 30

Enter the size of the files:


File 1: 12
File 2: 17
File 3: 25

File_no: File_size : Block_no: Block_size: Fragment


1 12 1 10 0
2 17 2 20 3
3 25 4 30 5

RESULT:
Thus the program for the memory allocation methods for fixed partition
Firstfit executed successfully.

28
Memory Allocation methods For Fixed Partition
Worstfit
Ex.No: 11.b
Date :02-05-25
AIM:
TowriteaCprogramforimplementationofFCFSandSJFschedulingalgorithms.
ALGORITHM:

Step1:Definethe maxas25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0,
bf[max],ff[max].Step3: Get the numberof blocks,files,sizeof the blocksusingforloop.
Step4:Inforloopcheckbf[j]!=1,ifso temp=b[j]-f[i]
Step5:Checktemp>=0,ifsoassignff[i]=j
breaktheforloop.Step6: Assign frag[i]=temp,bf[ff[i]]=1;
Step7: Repeatstep 4to step6.
Step8:Printfileno,size,blockno,sizeandfragment.St
ep9: Stop theprogram.

PROGRAM:
#include<stdio.
h>#include<con
io.h>#define
max
frag[max],b[max],f[max],i,j,nb,nf,temp;s
taticint bf[max],ff[max];
clrscr();
printf("\n\tMemoryManagementScheme-First
Fit");printf("\nEnter the number of
blocks:");scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-
\n");for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-
\n");for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);

29
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
temp=b[j]-
f[i];if(temp>
=0)
{
ff[i]
=j;b
reak
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:
Memory Management Scheme - Worst Fit
Enter the number of blocks: 4
Enter the number of files: 3
Enter the size of the blocks:
Block 1: 10
Block 2: 15
Block 3: 5
Block 4: 20
Enter the size of the files:
File 1: 12
File 2: 7
File 3: 17
File_no: File_size : Block_no: Block_size: Fragment
1 12 4 20 8
2 7 1 10 3
3 17 2 15 0

RESULT:
Thus the program for the memory allocation methods for fixed partition
Worstfit executed successfully.

30
Memory Allocation Methods For Fixed Partition
Best fit
Ex.no: 11.c
Date: 02-05-25

AIM:
TowriteaCprogramforimplementationofFCFSandSJFschedulingalgorithms.
ALGORITHM:

Step1:Definethe maxas25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0,
bf[max],ff[max].Step3: Get the numberof blocks,files,sizeof the
blocksusingforloop.Step4:Inforloopcheck bf[j]!=1,ifsotemp=b[j]-f[i]
Step5:Checklowest>temp,ifsoassignff[i]=j,highest=tempS
tep6:Assignfrag[i]=lowest,bf[ff[i]]=1,lowest=10000Step7:
Repeat step 4 to step 6.
Step8:Printfileno,size,blockno,sizeandfragment.St
ep9: Stop theprogram.

PROGRAM:
#include<stdio.
h>#include<con
io.h>#define
max
25voidmain()
{
intfrag[max],b[max],f[max],i,j,nb,nf,temp,lowest=1000
0;staticint bf[max],ff[max];
clrscr();
printf("\nEnterthenumberofblocks:");
scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-
\n");for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-
\n");for(i=1;i<=nf;i++)
{

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

31
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-
f[i];if(temp
[i]=lowest;b
f[ff[i]]=1;lo
west=10000
nFileNo\tFileSize
\tBlockNo\tBlockSize\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();
}

OUTPUT:
Enter the number of blocks: 4
Enter the number of files: 3

Enter the size of the blocks:


Block 1: 15
Block 2: 10
Block 3: 20
Block 4: 30

Enter the size of the files:


File 1: 12
File 2: 25
File 3: 10

FileNo FileSize BlockNo BlockSize Fragment


1 12 1 15 3
2 25 3 20 5
3 10 2 10 0

RESULT:
Thus the program for the memory allocation methods for fixed partition
best fit executed successfully.

32
C Progrm For Paging Technique Of Memory Management
Ex.No: 12
Date :05-05-25
AIM:
TowriteacprogramtoimplementPagingtechniqueformemorymanagement.
ALGORITHM:
Step1:Starttheprocess
Step2:Declarepagenumber,pagetable,framenumberandprocesssize.Step
3: Read the processsize, total number ofpages
Step4:Readtherelative address
Step5:Calculatethephysicaladdress
Step 6: Displaythe address
Step7:Stop theprocess
PROGRAM:

#include<stdio.h>
#include<string.h
>#include<pthrea
d.h>#include<stdl
ib.h>#include<uni
std.h>pthread_ttid
[2];
int
counter;pthread_mu
tex_tlock;
void*doSomeThing(void*arg)
{
pthread_mutex_lock(&lock);
unsignedlongi = 0;
counter+=1;
printf("\nJob%dstarted\n",counter);
for(i=0;i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n",
counter);pthread_mutex_unlock(&lo
ck);
returnNULL;
}
intmain(void)
{
int i =
0;inte
rr;

33
if(pthread_mutex_init(&lock,NULL)!=0)
{printf("\nmutexinitfailed\n");
return1;}
while(i<2)
{
err=pthread_create(&(tid[i]),NULL,&doSomeThing,NULL);i
f(err !=0)
printf("\ncan'tcreatethread:[%s]",strerror(err));
i++;
}
pthread_join(tid[0],
NULL);pthread_join(tid[1],
NULL);pthread_mutex_destroy(&
lock);return0;}

OUTPUT:
Job 1 started
Job 1 finished
Job 2 started
Job 2 finished

RESULT:

Thus the c progrm for paging technique of memory management executed


successfully.

34
Pagere Placement algorithms
FIFO
Ex.No: 13.a
Date: 07-05-25
AIM:
TowriteaCprogramforimplementationofFIFOpagereplacementalgorithm.

ALGORITHM:
Step1:Starttheprogram.
Step2:Declarethenecessaryvariables.
Step3: Enterthenumberof frames.
Step4: Enter thereferencestring endwith zero.
Step5:FIFO pagereplacement selectsthepagethathas beenin
memorythelongesttimeandwhenthe pagemust bereplaced theoldestpageis chosen.
Step6:Whenapageisbroughtintomemory,itis insertedatthetailofthe
queue.Step7:Initiallyall thethreeframesareempty.
Step8:Thepagefaultrangeincreasesasthenoofallocated
framesalsoincreases.Step9: Print thetotal numberof pagefaults.
Step10:Stoptheprogram.
PROGRAM:

#include<stdio.
h> intmain()
{
int
i=0,j=0,k=0,i1=0,m,n,rs[30],flag=1,p[30];s
ystem("clear");
printf("FIFOpagereplacementalgorithm. \\n");
printf("entertheno.offrames:");
scanf("%d",&n);
printf("enterthereferencestring:")
;while(1)
{
scanf("%d",&rs[i]);if(
rs[i]==0)
bre
ak;i
++;
}
m=i;for(j=0;j
<n;j++)p[j]=0
;
for(i=0;i<m;i++)

{
flag=1;for(j=

35
0;j<n;j++)if(p
[j]==rs[i])
{
printf("dataalreadyin page \n");
k++;
if(i1==
n)i1=0
;
for(j=0;j<n;j++)
{
printf("\n page
%d:%d",j+1,p[j]);if(p[j]==rs[i
printf("totalnopagefaults=%d",k);
}

OUTPUT:

FIFO page replacement algorithm.


Enter the number of frames: 3
Enter the reference string: 2 3 2 1 5 2 4 5 3 2 5 2 1 5

Page 1: 2
Page 2: 0
Page 3: 0

Page 1: 2
Page 2: 3
Page 3: 0

Page 1: 2
Page 2: 3
Page 3: 0

Page 1: 1
Page 2: 3
Page 3: 0

Page 1: 1
Page 2: 5
Page 3: 0

Page 1: 1
Page 2: 5
Page 3: 2

Page 1: 4
Page 2: 5

36
Page 3: 2

Page 1: 4
Page 2: 5
Page 3: 3

Page 1: 4
Page 2: 5
Page 3: 2*

Page 1: 1
Page 2: 5
Page 3: 2*

Page 1: 1
Page 2: 2
Page 3: 3

Page 1: 1
Page 2: 2
Page 3: 5

Page 1: 1*
Page 2: 2
Page 3: 5

Total number of page faults = 9

RESULT:
Thus the program for the pagere placement algorithms Fifo executed
successfully.

37
Pager Eplacement Algorithms for
LRU
Ex.No: 13.b
Date: 07-05-25
AIM:
TowriteacprogramtoimplementLRUpagereplacementalgorithm.
ALGORITHM:

Step1:Starttheprocess
Step2: Declarethesize
Step3:GetthenumberofpagestobeinsertedSte
p4: Get thevalue
Step5:Declare counterandstack
Step6: Select theleast recentlyused
pagebycountervalueStep7: Stack them
accordingtheselection.
Step8:Displaythevalues
Step9: Stoptheprocess
ROGRAM:

#include<stdio.
h> main()
{
intq[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[2
0];printf("Enterno of pages:");
scanf("%d",&n);
printf("Enterthereferencestring:")
;for(i=0;i<n;i++)scanf("%d",&p[
i]);
printf("Enternoofframes:")
;scanf("%d",&f);
q[k]=p[k];printf("\n\t
%d\n",q[k]);c++;
k++;
for(i=1;i<n;i++)
{c1
=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
if(c1==f)
{c++;
if(k<f)
{q[k]=p[
i];k++;

38
for(j=0;j<k;j++)
printf("\t%d",q[j
]);printf("\n");
}
else
{for(r=0;r<f;r++)
{c2[r]=0;
for(j=i-1;j<n;j--)
{if(q[r]!=p[
j])c2[r]++;
else
bre
ak;
}}
for(r=0;r<f;r+
+)b[r]=c2[r];f
or(r=0;r<f;r+
+)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[
j];b[j]=
t;
}}}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];printf("
\t%d",q[r]);
}
printf("\n");
}}}
printf("\nThenoofpage faultsis%d",c);
}

39
OUTPUT:

Enter number of pages: 12


Enter the reference string: 1 2 3 4 1 2 5 1 2 3 4 5
Enter number of frames: 3

1 2

1 2 3

1 2 3

1 2 3

1 2 3

1 2 5

1 2 5

1 2 3

1 2 3

1 2 4

1 2 4

The number of page faults is 9

RESULT:

Thus the program for the pager eplacement algorithms Lru executed
successfully

40
Page Replacement Algorithms
LFU
Ex.No: 13.c
Date: 07-05-25
AIM:
TowriteCprogramtoimplementLFUpagereplacementalgorithm.

ALGORITHM:

Step1:Starttheprocess
Step2: Declarethesize
Step3:GetthenumberofpagestobeinsertedSte
p4: Get thevalue
Step5:Declare counterandstack
Step6: Select theleast frequentlyused
pagebycountervalueStep7: Stack them
accordingtheselection.
Step8:Displaythevalues
Step9: Stoptheprocess
PROGRAM:

#include<stdio.
h>intmain()
{
intf,p;
int
pages[50],frame[10],hit=0,count[50],time[50];i
nti,j,page,flag,least,minTime,temp;
printf("Enternoofframes:");
scanf("%d",&f);
printf("Enternoofpages:");
scanf("%d",&p);for(i=0;i<
f;i++)
{
frame[i]=-1;
}
for(i=0;i<50;i++)
{
count[i]=0;
}
printf("Enterpageno:\n");
for(i=0;i<p;i++)

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

41
}
printf("\n");fo
r(i=0;i<p;i++)
{
count[pages[i]]+
+;time[pages[i]]
=i;flag=1;least=
frame[0];for(j=0
;j<f;j++)
{
if(frame[j]==-1||frame[j]==pages[i])
{
if(frame[j]!=-1)
{
hit++;
}
flag=0;frame[j]
=pages[i];break
;
}
if(count[least]>count[frame[j]])
{
least=frame[j];
}
}
if(flag)
{
minTime=50
;for(j=0;j<f;j
++)
{
if(count[frame[j]]==count[least]&&time[frame[j]]<minTime)
{
temp=j;minTime=time
[frame[j]];
}
}
count[frame[temp]]
=0;frame[temp]=pag
es[i];
}

42
for(j=0;j<f;j++)
{
printf("%d",frame[j]);
}

OUTPUT:
Enter number of frames: 3
Enter number of pages: 15
Enter page numbers:
701203042303212

7 -1 -1
7 0 -1
701
201
201
203
203
403
423
423
420
430
432
132
132

Page hit = 9

RESULT:
Thus the program for the page replacement algorithms
Lfu executed successfully.

43
File Organization Technique Single Level Directory

Ex.No: 14.a
Date: 10-05-25
AIM:
TowriteCprogramtoorganizethefileusingsingleleveldirectory.
ALGORITHM:

Step-1:Starttheprogram.
Step-
2:Declarethecount,filename,graphicalinterface.Step-
3:Read the numberof files
Step-4:Readthefilename
Step-5:Declaretherootdirectory
Step-6:Usingthefile eclipsefunction definethe filesinasingle
levelStep-7:Displaythe files
Step-8:Stoptheprogram

FLOWCHART:

PROGRAM:

#include<stdio.h>#
include<conio.h>#
include<stdlib.h>#
include<graphics.h
>voidmain()
{
intgd=DETECT,gm,count,i,j,mid,cir_x
;charfname[10][20];
clrscr();initgraph(&gd,&gm,"
c:/tc/bgi");cleardevice();setbk
color(GREEN);printf("enter
number of
files");scanf("&d",&count);if
(i<count)
//for(i=0;i<count;i++)
{
cleardevice();setbkcolor(GRE
EN);printf("enter%dfilename:"
,i+1);scanf("%s",fname[i]);
setfillstyle(1,MAGENTA);

44
mid=640/count;cir_x=mid
/3;bar3d(270,100,370,150
,0,0);
settextstyle(2,0,4);settextjustify(1
,1);outtextxy(320,125,"rootdirect
ory");setcolor(BLUE);
i++;
for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,cir_x,250);fille
llipse(cir_x,250,30,30);outt
extxy(cir_x,250,fname[i]);
}}
getch();
}

OUTPUT:
Enter number of files: 3
Enter 1st filename: Documents
Enter 2nd filename: Pictures
Enter 3rd filename: Music

RESULT:

Thus the program for the file organization technique single level
directory executed successfully.

45
File Organization Technique
Two level directory

Ex.No: 14.b
Date : 10-05-25
AIM:
TowriteCprogramtoorganizethefileusingtwoleveldirectory.
ALGORITHM:

Step-1:Starttheprogram.
Step-
2:Declarethecount,filename,graphicalinterface.Step-
3:Read the numberof files
Step-4:Readthefilename
Step-5:Declaretherootdirectory
Step-6:Usingthefile eclipsefunction definethe filesinasingle
levelStep-7:Displaythe files
Step-8:Stoptheprogram

PROGRAM:

#include<stdio.h>#
include<graphics.h
>structtree_elemen
t
{
charname[20];
int
x,y,ftype,lx,rx,nc,level;str
ucttree_element*link[5];
};
typedefstructtree_elementnode
;voidmain()
{int
gd=DETECT,gm;n
ode
*root;root=NULL;
clrscr();create(&root,0,"null",0,639,
320);clrscr();initgraph(&gd,&gm,"c
:\tc\bgi");display(root);
getch();clo
segraph();
}
create(node**root,int lev ,char *dname,int lx,intrx,intx)
{inti,gap;
if(*root==NULL)

46
{(*root)=(node*)malloc(sizeof(node));printf(
"enterthenameofdirfilename%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;(*roo
t)->x=x;
(*root)-
>lx=lx
;(*root)-
>rx=rx;for(i=
0;i<5;i++)
(*root)-
>link[i]=NULL;if((*r
oot)->ftype==1)
{if(lev==0||lev==1)
{if((*root)-
>level==0)printf("how
manyusers");else
printf(" how many
files");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

47
);setfillstyle(1,BL
UE);setcolor(14);i
f(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:
Enter the name of dir/filename: root
Enter how many users: 2
Enter the name of dir/filename: user1
Enter how many files (for user1): 3
Enter the name of dir/filename: file1_user1
Enter the name of dir/filename: file2_user1
Enter the name of dir/filename: file3_user1
Enter the name of dir/filename: user2
Enter how many files (for user2): 2
Enter the name of dir/filename: file1_user2
Enter the name of dir/filename: file2_user2

RESULT:
Thus the program for the file organization technique two level
directory executed successfully.

48
File Allocation Strategies
Sequential
Ex.No: 15.a
Date: 12-05-25
AIM:
TowriteaCprogramforsequentialfileforprocessingthestudentinformation.

ALGORITHM:

Step-1:Starttheprogram.
Step-2:Getthenumberof recordsuser wantto storein thesystem.
Step-3:UsingStandard Libraryfunctionopen thefileto writethe datainto
thefile.Step-4:Storethe enteredinformation in thesystem.
Step-5:Usingdo..Whilestatementand switchcaseto createtheoptionssuchas1-
DISPLAY,2.SEARCH,3.EXIT.
Step-
6:Closethefileusingfclose()function.Step-
7:Process it anddisplaytheresult.
Step-8:Stoptheprogram.

PROGRAM:

#include<stdio.
h>#include<con
io.h>typedefstru
ct
{int sno;
charname[25];intm1,m2,m3;
}STD;
voiddisplay(FILE*
);int search(FILE
*);voidmain()
{int
i,n,sno_key,opn;FI
LE*fp;
clrscr();
printf(“How many records
?”);scanf(“%d”,&n);fp=fope
n(“stud.dat”,”w”);for(i=0;i<
n;i++)
{printf(“Enterthestudentinformation:%d(sno,Name,M1,M2,M3):”,i+1);
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”);

49
do

{printf(“1-DISPLAY\n2.SEARCH\n3.EXIT\nYOUROPTION:“);
scanf(“%d”,&ope
n);switch(opn)
{
case1:
printf(“\n Student Records in the file
\n”);display(fp);
brea
k;cas
e2:
printf(“Readsnoofthestudenttobesearched:”);scanf(“%d
”,&sno_key);
if(search(fp,sno_key)){
printf(“success!! Record found in the
file\n”);printf(“%d\t%s\t%d\t%d\t%d\n”,s.sno,s.name,s.m1,s.
m2,s.m3);
}
else
printf(“Failure!!Record%dnotfound\n”,sno_key);
break;
case3:
printf(“Exit!!presskey”)
;getch();
brea
k;def
ault:
printf(“Invalidoption!!!Tryagain!!\n”)
;break;
}
}while(opn!=
3);fclose(fp);
}
Voiddisplay(FILE*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);
}
intsearch(FILE*fp,intsno_key)
{rewind(fp);while(fread(&s,sizeof(s
),1,fp))If(s.sno==sno_key)
return1;
return0;
}

50
OUTPUT:
How many records ? 3
Enter the student information: 1 (sno, Name, M1, M2, M3): 101 John 85 90 95
Enter the student information: 2 (sno, Name, M1, M2, M3): 102 Alice 75 80 85
Enter the student information: 3 (sno, Name, M1, M2, M3): 103 Bob 90 85 80
1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 1

Student Records in the file:


101 John 85 90 95
102 Alice 75 80 85
103 Bob 90 85 80

1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 2

Read sno of the student to be searched: 102


Success!! Record found in the file
102 Alice 75 80 85

1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 3

Exit!! Press any key

RESULT:
Thus the program for the file allocation strategies
Sequential executed successfully.

51
File Allocation Strategies For
Linked

Ex.No: 15.b
Date: 12-05-25
AIM:
TowriteaCprogramforrandomaccessfileforprocessingtheemployeedetails.
ALGORITHM:

Step-1:Starttheprogram.
Step-2:Getthenumber ofrecordsuser wanttostoreinthesystem.
Step-3:UsingStandard Libraryfunctionopenthe filetowritethe
dataintothefile.Step-4:Storethe enteredinformation inthe system.
Step-5:Usingdo..Whilestatement andswitchcasetocreatetheoptionssuchas1-
DISPLAY,2.SEARCH,3.EXIT.
Step-6:Closethefileusingfclose()
function.Step-7:Process itand displaythe
result.
Step-8:Stoptheprogram.

PROGRAM:

#include<stdio.
h>#include<con
io.h>#include<s
tring.h>structrec
ord
{
char
empname[20];int
age;
floatsalary;
};
typedefstructrecordpersonF
ILE*people;
voidmain()
{
person
employee;intI,
n;
FILE*fp;
printf(“How many
records:”);scanf(“%d”,&n);fp=fope
n(“PEOPLE.txt”,”w”);for(i=0;i<n;i

52
++)
{
printf(“Enter the employee information
:%d(EmpName,Age,Salary):”,i+1);scanf(“%s%d%f”,employee.empname,&employee.age,&e
mployee.salary);

fwrite(,&employee.sizeof(employee,1,people);
}
fclose(fp);
intrec,resu
lt;
people=fopen(“PEOPLE.txt”,”r”);
printf(“Which record do you want to read from
file?);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(“\nRECORD%d\n”,rec);
printf(“Given name:%s\n”,
employee.empname);printf(“Age:%dyears\n”,empl
oyee.age);printf(“Currentsalary:$%8.2f\n\n”,emplo
yee.salary);
}
else
printf( “\n RECORD %d not found
!\n\n”,rec);printf(“Which record do you
want(0to3)”):scanf(“%d”<&rec):
}
fclose(peopl
e):getch():
}

53
OUTPUT:
How many records ? 3
Enter the student information: 1 (sno, Name, M1, M2, M3): 101 John 85 90 95
Enter the student information: 2 (sno, Name, M1, M2, M3): 102 Alice 75 80 85
Enter the student information: 3 (sno, Name, M1, M2, M3): 103 Bob 90 85 80
1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 1

Student Records in the file:


101 John 85 90 95
102 Alice 75 80 85
103 Bob 90 85 80
s
1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 2

Read sno of the student to be searched: 102


Success!! Record found in the file
102 Alice 75 80 85

1-DISPLAY
2. SEARCH
3. EXIT
YOUR OPTION: 3

Exit!! Press any key

RESULT:
Thus the program for the file allocation strategies for
Linked is executed successfully.

54
File Allocation Strategies
Indexed
Ex.No: 15.c
Date :14-05-25
AIM:
TowriteaCprogramforrandomaccessfileforprocessingtheemployeedetails.

ALGORITHM:

Step-1:Starttheprogram.
Step-2:Getthenumber ofrecordsuser wanttostoreinthesystem.
Step-3:UsingStandard Libraryfunctionopenthe filetowritethe
dataintothefile.Step-4:Storethe enteredinformation inthe system.
Step-5:Usingdo..Whilestatement andswitchcasetocreatetheoptionssuchas1-
DISPLAY,2.SEARCH,3.EXIT.
Step-6:Closethefileusingfclose()
function.Step-7:Process itand displaythe
result.
Step-8:Stoptheprogram.

PROGRAM:
#include
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:
printf("enterindexblock\t"
);scanf("%d",&p);
if(f[p]==0)
{f[p]
=1;
printf("enter no of files on
index\t");scanf("%d",&n);
}
else
{
printf("Blockalreadyallocated\n"
);gotox;

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

scanf("%d",&inde[i]);for(
i=0;i<n;i++)if(f[inde[i]]=
=1)
{
printf("Blockalreadyallocated"
);gotox;
}
for(j=0;j<n;j++)f[i
nde[j]]=1;printf("\
nallocated");
printf("\nfileindexed"
);for(k=0;k<n;k++)
printf("\n %d-
>%d:%d",p,inde[k],f[inde[k]]);printf(" Enter 1
to enter more files and 0 to
exit\t");scanf("%d",&c);
if(c==
1)got
o
x;else
exit();
getch();
}

56
OUTPUT:
enter index block: 1
enter no of files on index: 3
2
3
4
allocated
file indexed
1->2:1
1->3:1
1->4:1
Enter 1 to enter more files and 0 to exit: 1
enter index block: 2
enter no of files on index: 2
3
5
allocated
file indexed
2->3:1
2->5:1
Enter 1 to enter more files and 0 to exit: 0

RESULT:
Thus the program for the file allocation strategies Indexed
executed successfully.

57
58

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy