You are on page 1of 97

Comput

erSc
ien
cea
ndEn
gin
eer
i
ng

CS8493-Ope
rat
i
ng Sy
ste
m

621319104039

R.
NI
SHANTH

2019-
2023

2020-2021
R.
NI
SHANTH

2nd 4th CSE

621319104039

Ope
rat
i
ngSy
ste
m
2020-
2021
1 Ba
sicofun
ixc
omma
nds 1

2 Sy
ste
mca
ll
sofun
ixope
rat
i
ngs
yst
em 5

3 CPr
ogr
amst
osi
mul
at
eun
ixc
omma
nds 12

4 She
llpr
ogr
ammi
ng 15

5 CPUs
che
dul
i
nga
lgor
i
thms 27

6 I
mpl
eme
nts
ema
phor
es 35

7 I
mpl
eme
nta
ti
onofs
har
edme
mor
yan
dIPC 37

8 Ba
nke
rsa
lgor
i
thmf
ord
eadl
ocka
voi
dan
ce 38

9 Si
mul
at
eforde
adl
ockde
tec
ti
on 41

1 I
mpl
eme
ntt
hre
adi
nga
nds
ync
hron
iza
ti
ona
ppl
i
cat
i
on 43

1 Con
ti
nguousme
mor
yal
l
oca
ti
ont
echn
ique
s 44

12 Si
mul
at
epa
gin
gte
chn
iqueofme
mor
yma
nage
men
t 50

1 Si
mul
at
eal
lt
hepa
ger
epl
ace
men
tal
gor
i
tms 51
14 I
mpl
eme
nta
llf
i
leor
gan
iza
ti
ont
echn
ique
s 57

15 I
mpl
eme
nta
ti
onoff
i
lea
ll
oca
ti
ons
tra
tegi
es 65

ADVANCEDEXPERI
MENTS

16 Si
mul
ar
ionofMVTa
ndMF
Tma
nage
men
tte
chn
ique
s 69

17 Si
mul
at
in
gthec
onc
eptofdi
ni
ng-
phi
l
osophe
rspr
obl
em 72

DESI
DNEXPERI
MENTS

1 Pa
cma
nga
me 75

2 Ca
len
darpr
ogr
am 78
KONGUNADUCOL
LEGEOFENGI
NEERI
NGANDTECHNOLOGY
(
AUTONOMOUS)
Thol
ur
pat
ti
(Po)
,Thot
ti
am(
Tk)
,Tr
i
chy(
Dt)-621215

COLLEGEVI
SI
ON&MI
SSI
ONSTATEMENT

VI
SI
ON
"
Tobe
comea
nIn
ter
nat
i
ona
ll
yre
nown
edI
nst
i
tut
i
oni
nte
chn
ica
leduc
ati
on,
res
ear
cha
ndde
vel
opme
nt,
byt
ran
sfor
min
gthes
tude
ntsi
nt
ocompe
ten
tpr
ofe
ssi
ona
lswi
t
hle
ade
rshi
psk
il
l
san
det
hi
cal
val
ues
."
MI
SSI
ON
 Pr
ovi
di
ngt
heBe
stRe
sour
cesa
ndI
nf
ras
truc
tur
e.
 Cr
eat
i
ngL
ear
nerCe
ntr
i
cEn
vir
onme
nta
ndc
ont
i
nuous-
Lea
rni
ng.
 Pr
omot
i
ngEf
fec
ti
veL
ink
swi
t
hIn
tel
l
ect
ual
san
dIn
dus
tri
es.
 En
ri
chi
ngEmpl
oya
bil
i
tya
ndEn
tre
pre
neur
i
alSk
il
l
s.
 Ada
pti
ngt
oCha
nge
sforSus
tai
nabl
eDe
vel
opme
nt.

1
COMPUTERSCI
ENCEANDENGI
NEERI
NG
VI
SI
ON
Topr
oduc
ecompe
ten
tsof
twa
repr
ofe
ssi
ona
ls,
aca
demi
ci
ans
,re
sea
rche
rsa
nde
ntr
epr
ene
urs
wi
t
hmor
alv
alue
sthr
oughqua
li
tye
duc
ati
oni
nthef
i
eldofComput
erSc
ien
cea
ndEn
gin
eer
i
ng.
MI
SSI
ON
 En
ri
cht
hes
tude
nts
'kn
owl
edgea
ndc
omput
i
ngs
kil
l
sthr
oughi
nnov
ati
vet
eac
hin
g-l
ear
ni
ng
pr
oce
sswi
t
hst
ate
-of
-ar
t-i
nf
ras
truc
tur
efa
cil
i
ti
es.
 En
dea
vourt
hes
tude
ntst
obe
comea
nen
tre
pre
neura
nde
mpl
oya
blet
hrougha
dequa
te
i
ndus
tryi
nst
i
tut
ein
ter
act
i
on.
 I
ncul
cat
i
ngl
eade
rshi
psk
il
l
s,pr
ofe
ssi
ona
lcommun
ica
ti
ons
kil
l
swi
t
hmor
ala
nde
thi
cal
val
ues
t
ose
rvet
hes
oci
et
yan
dfoc
usons
tude
nts
'ov
era
llde
vel
opme
nt.

PROGRAMEDUCATI
ONALOBJ
ECTI
VES
 PEO I
:Gr
adua
tess
hal
lbepr
ofe
ssi
ona
lswi
t
hex
per
ti
sei
nthef
i
eldsofSof
twa
re
En
gin
eer
i
ng,
Net
wor
ki
ng,
Dat
aMi
ni
nga
ndCl
oudc
omput
i
nga
nds
hal
lun
der
tak
eSof
twa
re
De
vel
opme
nt,
Tea
chi
nga
ndRe
sea
rch.
 PEO I
I
:Gr
adu
ate
swi
l
lan
aly
zepr
obl
ems
,de
signs
olut
i
onsa
ndde
vel
oppr
ogr
amswi
t
h
s
oun
dDoma
inKn
owl
edge
.
 PEOI
I
I:
Gra
dua
tess
hal
lha
vepr
ofe
ssi
ona
let
hi
cs,
tea
mspi
r
it
,l
if
e-l
ongl
ear
ni
ng,
goodo
ral
a
ndwr
i
tte
ncommun
ica
ti
ons
kil
l
san
dadoptc
orpor
atec
ult
ure
,cor
eva
lue
san
dle
ade
rshi
p
s
kil
l
s.
PROGRAMOUTCOMES:

1.En
gin
eer
i
ngk
nowl
edge
:Appl
ythek
nowl
edgeofma
the
mat
i
cs,
sci
enc
e,e
ngi
nee
ri
ngf
unda
men
tal
s,
a
nda
nen
gin
eer
i
ngs
pec
ial
i
zat
i
ont
othes
olut
i
onofc
ompl
exe
ngi
nee
ri
ngpr
obl
ems
.
2.Pr
obl
ema
nal
ysi
s:I
den
ti
fy
,for
mul
at
e,r
evi
ewr
ese
arc
hli
t
era
tur
e,a
nda
nal
yzec
ompl
exe
ngi
nee
ri
ng
pr
obl
ems r
eac
hin
gsubs
tan
ti
at
edc
onc
lus
ion
s us
ingf
i
rstpr
i
nci
pl
es ofma
the
mat
i
cs,n
atur
al
s
cie
nce
s,a
nde
ngi
nee
ri
ngs
cie
nce
s.
3.De
sign
/de
vel
opme
ntofs
olut
i
ons
:De
signs
olut
i
onsf
orc
ompl
exe
ngi
nee
ri
ngpr
obl
emsa
ndde
sign
s
yst
emc
ompon
ent
sorpr
oce
sse
stha
tme
ett
hes
pec
if
ie
dne
edswi
t
happr
opr
i
atec
ons
ide
rat
i
on
f
ort
hepubl
i
che
alt
han
dsa
fet
y,a
ndt
hec
ult
ura
l,s
oci
et
al
,an
den
vir
onme
nta
lcon
side
rat
i
ons
.
4.Con
duc
tin
ves
ti
gat
i
onsofc
ompl
expr
obl
ems
:Us
ere
sea
rch-
bas
edk
nowl
edgea
ndr
ese
arc
h
me
thod
sin
cludi
ngde
signofe
xpe
ri
men
ts,
ana
lys
isa
ndi
nt
erpr
eta
ti
onofda
ta,
ands
ynt
hes
isof

2
t
hei
nf
orma
ti
ont
opr
ovi
dev
ali
dcon
clus
ion
s.
5.Mode
rnt
oolus
age
:Cr
eat
e,s
ele
ct,a
nda
ppl
yappr
opr
i
atet
echn
ique
s,r
esour
ces
,an
dmode
rn
e
ngi
nee
ri
nga
ndI
Ttool
sin
cludi
ngpr
edi
ct
iona
ndmode
li
ngt
ocompl
exe
ngi
nee
ri
nga
cti
vi
ti
eswi
t
han
un
der
sta
ndi
ngoft
hel
i
mit
ati
ons
.
6.Thee
ngi
nee
ran
dsoc
iet
y:Appl
yre
ason
ingi
nf
orme
dbyt
hec
ont
ext
ualk
nowl
edget
oas
ses
s
s
oci
et
al
,he
alt
h,s
afe
ty,
lega
lan
dcul
t
ura
lis
sue
san
dthec
ons
eque
ntr
espon
sibi
l
i
ti
esr
el
eva
ntt
othe
pr
ofe
ssi
ona
len
gin
eer
i
ngpr
act
i
ce.
7.En
vir
onme
nta
nds
ust
ai
nabi
l
it
y:Un
der
sta
ndt
hei
mpa
ctoft
hepr
ofe
ssi
ona
len
gin
eer
i
ngs
olut
i
onsi
n
s
oci
et
ala
nde
nvi
r
onme
nta
lcon
tex
ts,
andde
mon
str
atet
hek
nowl
edgeof
,an
dne
edf
ors
ust
ai
nabl
e
de
vel
opme
nt.
8.Et
hi
cs:
Appl
yet
hi
cal
pri
nci
pl
esa
ndc
ommi
tt
opr
ofe
ssi
ona
let
hi
csa
ndr
espon
sibi
l
i
ti
esa
ndn
ormsof
t
hee
ngi
nee
ri
ngpr
act
i
ce.
9.I
ndi
vi
dua
lan
dte
am wor
k:F
unc
ti
one
ffe
cti
vel
yasa
nin
div
idua
l,a
nda
same
mbe
rorl
eade
rin
di
ver
set
eams
,an
dinmul
t
idi
sci
pl
i
nar
yse
tti
ngs
.
10.Commun
ica
ti
on:
Commun
ica
tee
ff
ect
i
vel
yonc
ompl
exe
ngi
nee
ri
nga
cti
vi
ti
eswi
t
hthee
ngi
nee
ri
ng
c
ommun
it
yan
dwi
t
hsoc
iet
yatl
ar
ge,s
ucha
s,be
inga
blet
ocompr
ehe
nda
ndwr
i
tee
ffe
cti
ve
r
epor
tsa
ndde
sig
ndoc
ume
nta
ti
on,ma
kee
ffe
cti
vepr
ese
nta
ti
ons
,an
dgi
vea
ndr
ece
ivec
lea
r
i
nst
ruc
ti
ons
.
11.Pr
oje
ctma
nage
men
tan
dfi
nan
ce:
Demon
str
atek
nowl
edgea
ndun
der
sta
ndi
ngoft
hee
ngi
nee
ri
ng
a
ndma
nage
men
tpr
i
nci
pl
esa
nda
ppl
ythe
set
oon
e’sownwor
k,a
same
mbe
ran
dle
ade
rinat
eam,
t
oma
nagepr
oje
ctsa
ndi
nmul
t
idi
sci
pl
i
nar
yen
vir
onme
nts
.
12.Li
f
eLon
gLe
arn
ing:Re
cogn
izet
hen
eedf
or,a
ndha
vet
hepr
epa
rat
i
ona
nda
bil
i
tyt
oen
gagei
n
i
nde
pen
den
tan
dli
f
e-l
ongl
ear
ni
ngi
nthebr
oade
stc
ont
extoft
echn
ologi
cal
cha
nge
.

B.
E(CSE)-PROGRAMSPECI
FI
COUTCOMES(
PSO'
s)

 PSO1:Pr
ofe
ssi
ona
lsk
il
l
s:St
ude
ntss
hal
lun
der
sta
nd,a
nal
yzea
nd de
vel
op c
omput
er
a
ppl
i
cat
i
onsi
nthef
i
eldofDa
taMi
ni
ng/
Ana
lyt
i
cs,
CloudComput
i
ng,
Net
wor
ki
nge
tc.
,t
ome
et
t
her
equi
r
eme
ntsofi
ndus
trya
nds
oci
et
y.
 PSO2:Compe
ten
cy:St
ude
ntss
hal
lqua
li
fya
ttheSt
ate
,Na
ti
ona
lan
dIn
ter
nat
i
ona
lle
vel
c
ompe
ti
ti
vee
xami
nat
i
onf
ore
mpl
oyme
nt,
highe
rst
udi
esa
ndr
ese
arc
h.

3
EXNO:1 BASI
CSOFUNI
XCOMMANDS
DATE:

AI
M:
Tos
tudya
nde
xec
uteUNI
Xcomma
nds
.

GENERALCOMMANDS:

Comma nd Func ti
on
date Usedtod isplaythec u rr
entsystemda te,ti
me.
date+%D Di
splaysd a t
eon l
y
date+%T Di
splaystimeo nl
y
date+%Y Di
splaysth eye a
rpa rto fdate
date+%H Di
splaysth eh ourpa rtofti
me
ca
l Cal
end aro fthecurren tmo n
th.
ca
l year Di
spla
y sc alendarfora ll
mo nt
hso fthes peci
fi
edyear
ca
l monthyea
r Di
splaysc alendarfort hespecifi
edmo nt
hofthey ea
r
who Logi
nd etail
sofa ll
us erss ucha sthei
rIP,Termi
nalNo,Userna
me,
whoa mi Usedtod isplaythelo gindetai
l
so ftheu ser
t
ty Usedtod isplaythet erminalname
uname Di
splaysth eOpe r
ati
n gSy st
e m
uname- r Showsv ers i
onnu mb e roft
heOS( k
e r
nel)
.
uname- n Di
splaysth ed oma i
nn ameo fthes er
ver
echo"tx
t" Di
splaysth eg i
vente xtont hes cr
een
echo$HOME Di
splaysth eu ser'
sh omed i
rector
y
bc Basi
cc al
c ulat
or.PressCt r
l
+dt oq ui
t
l
pfil
e Al
lowsth eu sertospo olajoba l
ongwi t
ho t
hersinapri
ntque
ue.
ma ncmd n
ame Manualfort hegivenc o mma nd.Pressqt oexit
-
histor
y Todispl
a ythec omma ndsusedb yth eusersin
celogon.
ex
it Exi
tfr
o mapr ocess.Ifs hel
li
sth eonlyprocessthenl
ogsout

DI
RECTORYCOMMANDS:

Comma n
d Functi
on
pwd Pathofthepresentworki
ngd i
rect
ory
mkdi
rdi
r Ad i
rector
yiscreat
edinthegivennameun dert
hec ur
ren
td i
r
ect
ory
mkdi
rdi
r1di
r
2 An umb erofsub-
dir
ector
i
esc anbec r
eate
dun deronestr
oke
cdsub
dir Chan geDir
e c
tory
.I
fthesubdirst
art
swith/thenpathsta
rtsf
romroot
(a
bso l
ute
)other
wisefr
omc ur
r en
tworkin
gd i
rect
ory.
c
d Tos wi
tchtotheh omedir
ectory
.
c
d/ Tos wi
tchtotherootdi
rect
ory.

UNI
XCOMMANDS:

Command Fun
cti
on
cd.
. Tomovebacktot
hepa
rentd
ir
ect
ory
r
md i
rsubdi
r Removesa
ne mpt
ysub-
di
rec
tor
y.

1
F
ILECOMMANDS:

Command Functi
on
ca
t>fi
l
ena
me Toc r
ea t
eaf il
ewi ths o mec onten ts.Toe n dtypi
ngpr essCtrl
+d.The>symbol
mea nsred i
rect
i
n go u tputtoaf il
e.(<f orinput)
catfil
ename Dis
playst hefi
lec on tents.
cat> >f
il
ename Usedt oa ppendc o nte n
tstoaf i
l
e
cps rcdes Copyf i
lestog i
ve nloc ati
o n.I
fa lr
e adye xists,
itwil
lbeov erwri
tt
en
cp- isr
cd e
s Warnst heu serpr i
o rtoo verwr it
ingt hed es t
i
n at
ionfi
le
cp- rsr
cd es Copiesth ee nt
i
redi re ct
or y
, al
litss ub -
directori
esa ndfi
l
e s
.
mvo l
dnew Toren amea ne xisti
n gfil
eord irectory.-iopti
o ncana l
sobeu s
ed
mvf 1f2f3d i
r Tomo veag roupo ffil
est oad ir
e ctory.
mv- vo l
dnew Dis
playn ameo fea chf i
lea sitismov ed.
r
mf i
le Usedt od ele
teaf il
eo rgroupo ff i
les.-iopti
onc ana l
sob eused
r
m* Tod el
etea ll
thefilesint hed i
r
e ctory .
r
m- r* Del
e t
esa llfi
l
esa nds ub-d i
rectories
r
m- f* Toforcibl
yr emov ee venwr ite
- pro t
ec t
edf i
les
l
s Li
stsallf
il
e sands u bd i
rectori
es( bluec olore d)i
ns ort
edma nne
r.
l
sn ame Toc heckwh et
h eraf il
eo rdi r
e ctorye xi
s t
s .
l
sn ame * Short-
h andn ot
a t
iont olisto utfil
e name sofas pec i
f
icpatt
e r
n.
l
s- a Li
stsa l
lfi
l
e sinc
ludin gh i
d denf i
les( fi
lesbe ginni
ngwi t
h.)
l
s- xd i
r
name Toh aves pecif
i
cl i
s t
ingo fad i
re ctory.
l
s- R Recursivelis
ti
ngo fa l
lfi
lesinth es ubdirector
ies
l
s- l Long l isti
ng s ho wing f i
le a c cessr i
gh t
s ( read/wri
te/
execu
te-r
wx for
user/gr
o up/others -
u go).
cmpfi
l
e1fi
l
e2 Usedt oc ompa ret wof il
es.Dis playsn othingiffi
lesareidenti
cal
.
wcfi
l
e I
tprodu cesas tati
s t
icsofl i
n es( l
),wor ds (
w) ,
a ndcharact
e r
s(c)
chmodpe
rmfi
le Chan gespe rmissionf orthes pe cif
iedfil
e.(r=4,w=2 ,
x=1)7 40fi
l
es e
tsal
l
ri
ghtsforu ser,
rea do n l
yf orgro upsa ndn orightsforothers

Thecommandscanbeco
mb i
nedus
ingt
hepi
pel
i
ne(|
)oper
ato
r.F
orexa
mple,nu
mb ero
fus
ersl
ogge
dinc
anb
eob
tai
ned
as.
who|wc-l
Fin
all
ytot
ermi
nat
etheuni
xse
ssi
onexec
utet
hecomma n
de x
ito
rlogou
t.

OUTPUT:
[admin@loca
lhosta
dmin]
$dat
e
SatApr 91 3:
03:
47I
ST201
1
[admin
@l oc
alho
stadmin]
$dat
e+%D
04/09/11
[admin
@l oc
alho
stadmin]
$dat
e+%T
13:
0 5:
33
[admin@loca
lhosta
dmin]
$dat
e+%Y
2011
[admin
@l oc
alho
stadmin]
$dat
e+%H
13
[admin@loca
lhosta
dmin]
$cal
April
20 11

2
S M T W TH F ST
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
[
a dmin@local
hostadmin]$wh o
root :
0 Apr 9 08:
41
admi n pts
/0 Apr 9 13:
00(scl
-64)
cse 1 pts
/3 Apr 9 13:
18(scl
-41.
smkf
omra.
com)
ece a pts
/4 Apr 9 13:
18(scl
-29.
smkf
omra.
com)
[
a dmin@local
hostadmin]$wh oami
admin pts/0 Apr 91 3:
00( s
cl-
64)
[
a dmin@local
hostadmin]$tty
/dev/pts
/0
[
a dmin@local
hostadmin]$uname
Lin
u x
[
a dmin@loca
lhostadmin]$uname- r
2.4.
20-8smp
[
a dmin@local
hostadmin]$uname- n
l
o c
a l
host
.l
ocaldomai
n
[
a dmin@local
hostadmin]$echo"Ho wa r
ey ou"
Howa r
ey ou
[
a dmin@local
hostadmin]$echo$ HOME
/home /admi
n
[
a dmin@loca
lhostadmin]$echo$ USER
admin
[
a dmin@local
hostadmin]$bc
bc1 .
06
Co pyr
ight1991-1994,1997,1998,2000FreeSoftwar
eFoun
d at
i
on,I
nc.
3+5
8
2%3
2
[
a dmin@local
hostloops]
$pwd
/home /admi
n /she
ll
scri
pts/l
oops
[
a dmin@local
hostadmin]$mk di
rfi
lt
er
[
a dmin@local
hostadmin]$ls
f
il
ter lis
t.
sh r egexpr shel
lscri
pt
s
[
a dmin@loca
lhostadmin]$cds he
ll
scri
pts/l
oops/
[
a dmin@local
hostloops]
$
[
a dmin@local
hostloops]
$c d
[
a dmin@local
host
admin]$[admin@local
host
l
o ops]
$c d/[ a
dmin@l o
calhost
/]$
[
a dmin@loca
lhost/]
$c d/h o
me /admin/s
hell
scri
pts
/l
oops
/[admin
@loca
lhos
tloo
ps]
$cd.
.
[
a dmin@local
hostshe l
l
scri
pts
]$
[
a dmin@local
hostadmin]$rmd i
rf
il
ter
[
a dmin@local
hostadmin]$ls

3
l
i
st.
sh r
ege
xpr s
hel
l
scr
i
pts

4
[
a dmi n
@loc al
hostadmi n
]$c at>greet
hie c
e -
a
wishingut heb est[a
dmi n
@l ocal
host
admi n]
$c atgreethiece-a
wishingut heb est
[
a dmi n
@loc al
hostadmi n
]$c at>>greet
bye
[
a dmi n
@loc al
hostadmi n
]$c atgreet
hie c
e -
a
wishinguth eb e
st
bye
[
a dmi n
@loc al
hostadmi n
]$ls
greet l
i
st.
sh r egexpr shel
ls
c r
ipts
[
a dmi n
@loc al
hostadmi n
]$ls- a
. . b ash_l
o gout . canna.gtkr
c r egexpr .
vi
min
fo.
tmp
.
. . b ash_prof
il
e . ema cs.kde s hel
lscri
pts .
xemacs
.
ba sh_his
tory .
bashrcg r
eet l ist
.s
h . vi
minf
o
[
a dmi n
@loc al
hostadmi n
]$ls- l
t
ot al16
-r
w- rw-r-
-1 adminadmin3 2 Apr1114:
52 gr eet
-r
w- rw-r-
-1 adminadmin3 0 Apr413:
58 l i
st
.s
h
[
a dmi n
@loc al
hostadmi n
]$c pg r
eet.
/ r
egexpr/
[
a dmi n
@loc al
hostadmi n
]$ls
greet l
i
st.
sh r egexpr shel
ls
c r
ipts
[
a dmi n
@loc al
hostadmi n
]$ls./re
gexpr
de mog reet
[
a dmi n
@loc al
hostadmi n
]$c p-igreet.
/regexpr/
cp:ov er
write'gr
ee t
'
?n
[
ad min@loc al
hostadmin]$mvgr e
etgre e
t.
txt
[
a dmi n
@loc al
hostadmi n
]$ls
greet.t
xt l i
st.
sh r egexpr shel
ls
c r
ipts
[
a dmi n
@loc al
hostadmi n
]$mvgr eet
.
txt./
regex pr
/
[
a dmi n
@loc al
hostadmi n
]$ls
l
i
s t.
shr eg
ex prshell
scr
ipts
[
a dmi n
@loc al
hostadmi n
]$ls./re
gexpr/
de mo gr
eet.
txt
[
a dmi n
@loc al
hostadmi n
]$wcl is
t.
sh
she l
l
s cr
i
pts
4 9 30l
ist.
sh

RESULT:
Thust
hes
tudya
nde
xec
uti
onofUNI
Xcomma
ndsha
sbe
enc
ompl
et
eds
ucc
ess
ful
l
y.

5
EX.
NO:2 SYSTEMCAL
LSOFUNI
XOPERATI
NGSYSTEMDATE:
(
a)for
k()

AI
M:
Towr
i
tet
hepr
ogr
amt
ocr
eat
eaCh
il
dPr
oce
ssus
ings
yst
emc
all
for
k()
.

ALGORITHM:
St
ep1:Decla
rethevari
abl
epid.
St
ep2:Getthepi
dv al
ueusingsy
ste
mc a
llf
ork(
).
St
ep3:I
fpidval
ueisles
sthanzerothenpri
ntas“Fo
rkfai
l
ed”.
St
ep4:El
seifpi
dv a
lueisequal
tozeroin
cludethenewproc
essint
hesy
ste
m’sfi
l
eus
ingexe
clpsys
temcal
l
.
St
ep5:El
seifpi
disgreate
rthanzer
otheniti
stheparen
tproces
sandi
twai
tst
il
lt
hec
hil
dcomple
tesusi
ngt
he
systemcall
wa i
t(
)
St
ep6:Thenpri
nt“Chil
dcomplet
e”.

PROGRAM:

#i
ncl
ud e<
stdi
o.
h>
#i
ncl
ud e<
stdl
ib.
h>
#i
ncl
ud e<
unis
td.
h>
voi
dma in
(i
ntargc,
char*ar
g[]
)
{
i
ntpid;
pi
d =
fork
()
;
i
f(
pid<0)
{
pr
in
tf(
"f
o r
kfai
l
ed");
ex
it
(1)
;
}
el
seif
(pi
d==0)
{
ex
eclp(
"whoami",
"l
s"
,NULL)
;
ex
it
(0)
;
}
el
se
{
pr
in
tf(
"\nProcessi
di s-
%d\n",
get
pi
d(
))
;
wai
t(
NUL L);
ex
it
(0)
;
}
}

OUTPUT:
[
cse
6@loc
alhos
tPgm]
$ccpr
og4
a.c

[
cse
6@l
oca
lhos
tPgm]
$./
a.
out

Pr
oce
ssi
dis
-55217

RESULT:
Thust
hepr
ogr
amwa
sex
ecu
teda
ndv
eri
f
ieds
ucc
ess
ful
l
y.
6
(
b)e
xec
()

AI
M:
Towr
i
tet
hepr
ogr
amt
oimpl
eme
ntt
hes
yst
emc
all
exe
c()
.

AL
GORITHM:
St
ep1 :
Inc
ludethenecessa
ryheaderf
il
es.
St
ep2 :
Pri
ntexecuti
onofexecsyst
emc al
lf
ort
hedat
eUnixcommand.
St
ep3 :
Executetheexe
c l
pfunct
i
onu s
ingthea
ppr
opri
at
es y
nta
xfort
heUn
ixc
omma
ndda
te.
St
ep4 :
Thes yst
emd at
eisd i
spl
aye
d.

PROGRAM:
#i
ncl
ude<
stdi
o.
h>
#i
ncl
ude
<uni
std.
h>
mai
n()
{
pr
i
ntf
(“
\nexecsyst
emc al
l”
);
pr
i
ntf
(“
dis
play
ingt
hed at
e”)
;
ex
ecl
p(“/bi
n/d
ate”
,“da
te”
,0);
}

OUTPUT:
SatDec1402:
57:
38I
ST20
10

RESULT:
Thust
hepr
ogr
amwa
sex
ecu
teda
ndv
eri
f
ieds
ucc
ess
ful
l
y.
7
(
C)ge
tpi
d(
)

AI
M:

Towr
i
tet
hepr
ogr
amt
oimpl
eme
ntt
hes
yst
emc
all
sge
tpi
d(
)an
dge
tppi
d(
).

ALGORITHM:
St
ep1: Declar
eth evari
ab l
espid,parentpid, c
hil
dida n
dgr a
n dchili
d.Ste
p
2:
Ge tthechi
ldidv a
lueu si
ngs yst
e mc all
fork(
).
St
ep3: I
fchil
didv al
ueisl es
st ha
nz e r
ot he
npr i
ntas“errora tfor
k()chi
ld”
.
St
ep4: I
fchil
did!
= 0thenus i
ngg etpi
d (
)systemc al
lgetthepr oc e
ssid.Step
5:
Print“Iampa r
e nt
”a n
dpr in
tthepr ocessid.
St
ep6: Getthegrandc hil
didv al
ueu si
n gsystemc al
lfor
k().
St
ep7: I
ftheg r
andc hil
didv al
ueisle s
st hanzerothenpr i
nta s“err
oratfork
()g
randchi
l
d”.
Ste
p8:
I
ft
heg r
andch i
l
did !
=0the nusin
gge tpidsystemc al
lgetth epro c
essid.
St
ep9: Assigntheva l
ueofpi dtomypi d.
St
ep10 :Pri
nt“Iamc hi
l
d”a ndpri
n tthevalueofmypi d.Step
11:
Ge tmypa rentpi
dv alueus i
ngs yst
emc al
lget
ppid()
.Ste p
12:
Pr i
nt“Mypa r
e nt

spr ocessid”a ndit
sv al
u e
.
St
ep13 :Els
epr i
nt“Iamt hegr andc hi
l
d ”
.
St
ep14 :Gettheg ra
n dch i
l
d‟sproc essidus i
nggetpi
d (
)an dpr i
nti
tas“ myproce
ssid”
.
St
ep1 5:Gettheg r
andc h i
l
d‟spare n
tpro ce
s si
du si
ngg etppid()andpri
ntita
s“myparent

sproce
ssi
d

PROGRAM:
#i
ncl
ude<s
tdio.
h>
#i
ncl
ude<u
nist
d.h>
#i
ncl
ude<s
tdli
b.
h>
i
ntmain
()
{
i
ntpi
d;
pi
d=f
ork()
;
i
f(
pi
d==-1)
{
pe
rro
r(“
for
kfa
il
ed”
);
exi
t(
0);
}
i
f(
pid=
=0)
{
pri
nt
f(
“\nChi
ldpro
c e
ssisunderex
ecuti
on”);
pri
nt
f(
“\nProce
ssidofthechi
l
dprocessis%d”,getpi
d())
;
pri
nt
f(
“\nProce
ssidofthepar
entproc
e ssis%d”,
ge t
ppid()
);
}
el
se
{
pri
nt
f(
“\nPar
entproces
sisunderex
ecu t
i
on ”
);
pri
nt
f(
“\nProce
ssidofthepar
entproc
e ssis%d”,
ge t
pid()
);
pri
nt
f(
“\nPro
cessidofthechi
l
dprocessinpare
ntis%d” ,pi
d(
))
;
pri
nt
f(
“\nProce
ssidofthepar
entofparenti
s%d ”
,getppid(
))
;
}
re
turn
(0);
}

8
OUTPUT:
Ch i
l
dpr oce
ssisunderexecut
ion
Processidofthechi
l
dproc e
ssis93 14
Processidofthepa
rentpr
oc essi
s93 13
Parentproces
sisunderexecuti
on
Processidofthepar
entprocessis9313
Processidofthechi
l
dproc e
ssinpa re
nti
s931
4
Processidofthepar
entofparentis2825

RESULT:
Th
usthepr
ogr
amwa
sex
ecut
eda
ndv
eri
f
ieds
ucc
ess
ful
l
y.

9
(
d)ex
it
()a
ndwai
t(
)
AI
M:
Towri
tet
hepr
ogr
amt
oimpl
eme
ntt
hes
yst
emc
all
swa
it
()a
nde
xit
().

ALGORI THM:
Step1:Declarethev ar
ia
ble
spi da n
di asint
egers.
Step2:Getth echi
ldidval
ueus ingthesystemc al
lfor
k()
.
Step3:I
fchil
di dvaluei
slessthanz erothenpri
nt“for
kfai
led”.
Step4:Els
ei fchi
ldidval
ueise qualtozero,i
ti
st hei
dv a
lueofthec hi
l
dandthe
ns t
artt
hechil
dproce
sstoexec
uteand
perf
ormSt eps6&7 .
Step5:Els
epe r
formSt e
p8.
Step6:Usef orloopforal
mo stfi
vec hi
l
dproc e
ss est
ob eca l
l
ed.
St
ep7:Aftere xecut
ionoftheforloopthenprint“ch
il
dproc e
sse nds”
.
Step8:Execu t
ethes yst
emc allwait
()toma kethepa r
enttowa i
tfort
hechi
l
dprocesstogetover
.
Step9:On c
et hec hi
ldproc
es sesareterminat
ed,theparentter
minate
sandhencepri
nt“Pa
rentpr
ocessen
ds”.
Step10:Aft
e rboththepa r
enta ndthechidprocessesgettermin
atedite
xec
utethewait
()syst
emc al
lt
opermanen
tl
y
getdel
etedfromt heOS.

PROGRAM:

#i
ncl
ude<s
tdi
o.
h>
#i
ncl
ude<u
nis
td.
h>
mai
n(){
i
nti
,pi
d;
pi
d=f
ork
();
i
f(
pi
d==-1)
{
perr
or(
“for
kfai
le
d”);
exi
t(
0);
}
el
seif(
pi
d==0)
{
pri
nt
f(“
\nChil
dpr o
c es
ss t
art
s‟)
;
fo
r(i
=0;i
<5;i
++)
{
pri
nt
f(“
\nChil
dpr o
c es
s%di scal
l
ed”
,i
);
}
pri
nt
f(“
\nCh i
l
dproc e
sse n
ds”)
;
}
el
se
{
wait
(0)
;
pri
nt
f(“
\nPa r
entproces
se nds
”);
}ex
it
(0);
}

OUTPUT:
Chi
ldproce
sss t
art
s
Chi
ldproce
ss0isc al
l
ed
Chi
ldproce
ss1isc al
l
ed
Chi
ldproce
ss2isc al
l
ed
Chi
ldproce
ss3isc al
l
ed
Chi
ldproce
ss4isc al
l
ed
Chi
ldproce
sse nd
s
Par
entproces
se nds

RESULT:
Th
usthepr
ogr
amwa
sex
ecut
eda
ndv
eri
f
ieds
ucc
ess
ful
l
y.

1
1
(
e)Sta
t:
AI
M:
ToEx e cu t
eaUn i
xComma n
di na‘C’pr ogramu si
ngstat
()sy
ste
mca
ll
.
ALGORITHM:
1.Sta rtthepr og r
a m
2.De c l
aret hev ariablesforthes t
ruct
u restat
3.Alloc atet hes i
zef orthefi
leb yusi
ngma l
l
ocf un
cti
on
4.Ge tt hei nputoft h ef i
l
ewho ses t
ati
s ti
cswa nttobefounde
d
5.Re pe att hea boves t
epu nti
lsta
ti
sti
csoft hef i
l
esareli
st
ed
6.Stopt hepr og r
a m.
PROGRAM:
#i
nclu de< stdio.h>
#i
nclu de< un i
std.h>
#i
nclu de< sy s
/ty pes.h>
#i
nclu de< sy s/stat.
h>
#i
nclu de< fcntl
.h>
#i
nclu de< stdli
b.h >
i
ntma i
n (
v oid)
{
char* path ,
pa th1 [
1 0];
st
ructs t
a t* nf
il
e ;
nf
il
e=( str
u c tstat* )ma l
l
oc(sizeof(
str
uc tstat
))
;
pri
ntf
("e ntern ameo ffi
lewh oses t
si
sti
csh asto"
);
scanf("%s ",
pa th1);
st
at(pa th1 ,
n f
il
e )
;
pri
ntf
( "
u se rid%d \n",
n fi
l
e->st
_ ui
d);
pri
ntf("bl
ock
si
ze:%d \n "
,nfi
le->s t
_b l
ksize)
;pri
ntf
("
lasta ccess
ti
me%d\ n "
,nfi
le->s t
_a t
ime )
;
pri
ntf
( "
timeofl a stmo dif
i
cati
on%d \n",
nfil
e -
>st
_ a
ti
me )
;
pri
ntf
( "
po rd uctionmod e%d\ n
",
nfi
le-
>st_mo de )
;pri
nt
f(
"si
ze
offi
l
e%d\ n ",
nfil
e -
>st_ si
ze);
pri
ntf
( "
n umb erofl inks:%d\n"
,nfi
l
e->st
_n l
ink);
}

OUTPUT:
ente
rn ameo ffi
l
ewh oses t
si
sti
cshast
ost
at.
c
useri
d6 21
bl
ocks i
ze:4096
la
stacc es
st i
me1 145148485
ti
meo flastmodif
i
c at
i
on1 1451484
85
porducti
onmo de3 3204
si
zeo ffi
l
e6 54
numbe rofli
nks
:1

RESULT:
Th
ust
hepr
ogr
amf
ors
tats
yst
emc
all
hasbe
ene
xec
ute
dsu
cce
ssf
ul
ly
.

1
1
(
f)ope
ndi
r
()a
ndr
eddi
r
()
AI
M:

Towr
i
tet
hepr
ogr
amt
oimpl
eme
ntt
hes
yst
emc
all
sope
ndi
r
(),
rea
ddi
r
().

ALGORITHM:
St
ep1: St
art
.
St
ep2: I
nthema i
nfunct
i
onpa s
sthear
gumen
ts.
St
ep3: Cr
eatestr
uctur
eass t
atbuf
fan
dthev
ari
abl
esa
sin
tege
r.
St
ep4: Usi
ngtheforl
oop,
in
it
ia
li
zat
io
n

PROGRAM:
#i
ncl
ude <st
d i
o.
h >
#i
ncl
u d
e <sy
s /
types.
h>
#i
ncl
ude <sys/di
r.
h>
voi
dma i
n(
intage,
char*ar
gv[
])
{
DIR* di
r;
st
ructdir
ent*rddir
;
pr
int
f("
\nL i
sti
ngthed i
r
ector
ycont
ent
\n"
);
di
r=
ope ndir
(ar
g v[
1])
;
whi
le((
rddi
r=readdi
r(
dir
))
!=
NUL L
)
{
pr
int
f("
%s \t
\n"
,rddi
r-
>d_name)
;
}
cl
osedi
r (
di
r);
}

OUTPUT:

RP
ros
hi.
cfi
r
st.
c
pk6.
cf2
abcFI
LE1

RESULT:
Thust
hepr
ogr
amwa
sex
ecu
teda
ndv
eri
f
ieds
ucc
ess
ful
l
y.

1
2
EXNO:
3 CPROGRAMSTOSI
MULATEUNI
XCOMMANDSLI
KELS,
GREP.
DATE:

(
a)LS:
AIM:
Toimplementl
sc omma ndinc.
ALGORITHM:
STEP1: I
ncl
udead i
rent.
hheaderfi
l
e.STEP
2:Cre
a t
eav ar
ia
bleDIRa spoint
erSTEP3:
Creat
eas tr
uctur
epointerofdi
rent
STEP4 :Usin
go pendirfunct
i
on,openthecur
rentdi
r
ector
y
STEP5 :Readt hedirect
oryforfi
l
esu si
ngr
eaddi
rfunc
ti
on
STEP6 :Di
spl
ayitti
l
ltheendo ft
hefi
le.

PROGRAM:
#incl
ude<s t
dio.
h>
#incl
ude<d i
rent.
h>
#incl
ude<e r
rno.h>
#incl
ude<sys/ s
tat
.h>
intmain(
intargc,
char**argv)
{
DIR*dir
;
structdir
e nt* di
r
ent;char*whe r
e=NULL;
i
f(ar
gc==1)wh ere=
get_cur
rent
_di
r_n
ame()
;
else
wh ere=a
rg v
[1];
i
f(NUL L=
=(dir
= ope
ndir
(where)
))
{
fpri
ntf
(st
de r
r,
"%d(%s)opendi
r%sfai
le
d\n"
,
err
no,
st
rer
ror
(er
rno)
,
whe
re)
;
retur
n2 ;
}
wh i
le(
NUL L!
=( di
r
ent=r
e a
ddir
(di
r)
))
{
prin
tf(
"%s\n",
diren
t->
d_ na
me )
;
}
closedi
r(
dir)
;
retur
n0;
}

OUTPUT:
openr
ea ddi
r
.c
fi
l
e.
txt
opencl
ose.
c
st
aff
rr
.cfi
fo.
c
example.
dat
newgetpi
d.
c

RESULT:
Thusthes
yst
emc
all
pro
gra
mha
sbe
ene
xec
ute
dsuc
ces
sful
l
y.

1
3
b)GREP:

AI
M:
Toimpleme ntthegrepcomma ndinc
ALGORITHM:
STEP1 :Obt aintherequi
redpa t
terntobesea r
che
dandf
il
enamef r
omtheuser
STEP2 :Ope nthefil
eandreadt hecon s
tan
tsusedbywo
rdtil
lt
heendofthef
i
le.
STEP3 :Ma t
cht hegiv
enpa t
ternwiththereadworda
ndi
fitmatc
hes,di
spl
ayt
heli
neofoc
cur
anc
eSTEP
4:Dot hi
st i
llt
hee ndofthefi
leisreached.
PROGRAM:
#i
nclude<s t
d i
o.
h >
#i
nclude<stri
ng.h>
i
ntma in
(intargv,cha
r*a r
gs[]
)
{
FI
LE*f ;
charstr
[10 0];
charc;
i
nti,
fl
ag,
j,m,k;
chararg[]
= "
HI";
chartemp[ 30];
i
f(
argv<3)
{
pri
ntf
("
us ageg rep<s><val
.
txt
>\n");
ret
urn;
}
f=
fopen(args[2],
"r
");
whil
e(!
feof(f
))
{i
=0;
whil
e(1)
{
fs
can f
(f
,
"%c ",
&c )
;
i
f(
feof(
f))
{
st
r[i
++]='
\0 '
;
break;
}
i
f(
c== '
\n'
)
{
st
r[i
++]='
\0 '
;
break;
}
st
r[i
++]=c;
}
i
f(
strl
en(str
)>=strl
en(ar
gs[1]
))
fo
r(k=0;
k<= st
rl
e n(
str
)-s
trl
en(
args[1]
);
k++)
{
fo
r(m= 0;
m< strl
en(ar
gs[1]
);
m++)
te
mp[ m]= str
[k+m];temp[m]='
\0';
i
f(
strcmp(te mp,args[
1])
==0)
{

1
4
pri
nt
f("
%s\
n",
st
r)
;
bre
ak;
}}
}
re
turn0;
}

OUTPUT:

[s
kec25@local
host~]$./a.
outpri
ntsta
t.
c
pri
nt
f("
ent
ernameo ffi
l
ewh o s
es ts
ist
ic
sha sto"
);
pri
nt
f("
useri
d%d \n"
,nf
i
le->s
t_uid
);
pri
nt
f("
bl
ock s i
z e :%d\n",
nfi
le
->st
_blks
ize)
; pri
ntf
("
l
a s
t
accesstime %d \n
",
nfi
le-
>st_at
ime);pri
ntf
("
ti
me oflast
mo di
fi
cat
i
on %d \n"
,nfi
l
e->st
_ati
me )
; pr i
nt
f(
"por
ducti
on
mo de%d\ n
",
nfi
l
e -
>st
_mod e);pr
int
f(
"si
zeoffi
l
e
%d\n",
nf
il
e->
st_s
ize)
;
pri
nt
f("
nu,
mb erofl
ink
s:%d\n",
nfi
l
e->st
_nl
in
k);

RESULT:
Thusthepr
ogr
amha
sbe
ene
xec
ute
dsu
cce
ssf
ul
ly
.

1
5
EX.NO:
4 SHEL
LPROGRAMMI
NG
DATE:
CONDI
TI
ONALSTATEMENTS
A-ODDOREVEN

AI
M:
Towr
i
teas
hel
lpr
ogr
amt
och
eckwh
eth
ert
hegi
venn
umb
eri
sod
dore
ven
.

ALGORITHM:
STEP1:Readt
heinputnumb er.
STEP2:Per
for
mmo dul
ardiv
isi
ononin
putnumberb
y2.
STEP3:I
fr
ema i
nderi
s0pr i
ntthenumberi
seve
n.
STEP4:El
sepri
ntn
u mberisodd.
STEP5:St
optheprogra
m.

PROGRAM:
echo-n"Ent
eranon
-zer
onu
mbe
r:"
readnum
rem=è
xpr$num%2 `i
f
[$rem-eq0]
then
echo"$numisEv
en"
els
e
echo"$numisOdd"
fi

OUTPUT:
[admin
@local
hostde
cis
ion
]$shod
dev
en.
sh
En t
eranon
-zeronumber:12
12isEven

RESULT:
Th
usthes
hel
lpr
ogr
amf
oro
ddo
rev
enh
asb
eene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

1
6
B-BI
GGESTOF3NUMBERS

AI
M:
Towr
i
teas
hel
lpr
ogr
amt
ofi
ndbi
gge
sti
nth
reen
umb
ers
.

AL
GORITHM:
STEP1:ReadTh eThreeNumber
s.
STEP2:I
fAIsGr ea
terThanBAndAIsGr
eate
rThanCThe
nPr
i
ntAI
sBi
g.
STEP3:El
seIfBisgreate
rTha
nCThe nCIsBi
g.
STEP4:El
sePri
n tCIsBig.
STEP5:St
opt heProgr
am

PROGRAM:
#Biggestusin
glogi
calexpr
essi
on
echo-
n" Giveval
ueforABa ndC:"
r
eadabc
i
f[$a-gt$ b-a$a-gt$c]
t
hen
echo"
Ai stheBiggestnumber
"
el
i
f[$b-g t$c]
t
hen
echo"
Bi stheBigge
s tn
u mber
"
el
se
ech
o"Ci stheBiggestn
u mber
"
f
i

OUTPUT:
[admi
n@l
ocal
hostdeci
si
on]
$shbi
g3.
sh
Giv
eval
ueforABa ndC:434
CistheBi
ggestnumber

RESULT:
Thu
sthes
hel
lpr
ogr
amf
orb
igg
esto
fth
reen
umb
ersha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

1
7
C-L
EAPYEAR

AI
M:
Towr
i
teas
hel
lpr
ogr
amt
ofi
ndt
hel
eapy
ear
.

ALGORITHM:
STEP1:St
artt
heprogram
STEP2:Readyea
r
STEP3:i
fyear
%4=0a n
dy ea
r%10
0!=
0ori
fye
ar%4=
0an
dye
ar%40
0=0t
hengot
ost
ep4e
lseg
otos
tep5
STEP4:pr
i
ntaleapyear
STEP5:pr
i
ntnotaleapyear
STEP6:St
optheprogram

PROGRAM:
#L eapyear
echo-n"Ent
eray ear:"
readyear
rem1=è
xpr$year%4 `
rem2=è
xpr$year%1 00`
rem3=è
xpr$year%4 00`i
f
[$rem3-eq0]
then
echo"$yea
risaL eapYear
"
eli
f[$r
em2- ne0- a$r
em1- e
q0]
then
echo"$yea
risaL eapYear
"
else
echo"$yea
risNo tale
apyear"
fi

OUTPUT:
[admin
@loca
lhos
tdec
isi
on]
$shl
eap.
sh
En t
eraye
ar:1900
19 00i
sNotale
apyear

RESULT:
Th
usthes
hel
lpr
ogr
amf
orL
eapy
earo
rno
tha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

1
8
D-STRI
NGCOMPARI
SON

AI
M:
Towr
i
teas
hel
lpr
ogr
amt
oco
mpa
ret
hes
tri
ng.

AL
GORITHM:
STEP1:Ta
ketwos t
ri
ngsasin
put.
STEP2:Compar
et het
wos t
ri
ngs
STEP3:Di
spl
aytheres
ultwhet
herbo
tha
ree
qua
l,orf
i
rsts
tri
ngi
sgr
eat
ert
hant
hes
econ
dort
hef
i
rsts
tri
ngi
s
le
sstha
nthesec
on dst
ri
ng
STEP4:Ex
it
.

PROGRAM:
ec
ho-n"Enterthef
ir
ststr
i
ng: "
r
eads1
ec
ho-n"Enterthesec
onds t
ri
ng:"
r
eads2
i
f[
$s1=$ s2]
t
hen
ec
ho"Str
in
g sareth
es ame"
el
seecho"Str
in
gsa r
edist
inc
t"
f
i

OUTPUT:
[admin
@loca
lhos
td e
cisi
on]
$shs
trc
omp.
sh
Entert
hefi
rs
tstr
ing:cse
Entert
hesecondstr
ing:CSE
Str
ingsar
edist
i
nct

RESULT:
Thu
sthes
hel
lpr
ogr
amf
ors
tri
ngc
ompa
ri
sonha
sbe
ene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

1
9
LOOPS

A—ARMSTRONGNUMBER

AI
M:
Towr
i
teapr
ogr
amt
ofi
ndt
hen
umb
eri
sAr
mst
ron
gorn
ot.

ALGORITHM:
STEP1:i
nputn
STEP2:s=0, a=n
STEP3:whil
e(n
> 0)
begin
rem= n%10
s=s*10+rem
n=n/10
end
STEP4:i
f(
s==a)
print'
i
ti
sapa l
i
ndr
ome'
els
e
pri
nt'
iti
sn otapa
li
ndr
ome
'
STEP5:st
op

PROGRAM:
#Arms tr
on gn umberus
ingwh i
l
eloop
echo-n"En t
eran umber:"
r
eadn
a=$n
s=0
whi
le[$ n-gt0]
do
r
=èxpr$n%1 0`
s=è
xpr$s+\ ($r\*$r\
*$ r\)
`
n=è
xpr$ n/1 0`
done
i
f[$a- e
q$ s]
t
hen
echo"Arms tr
ongNu mber"
el
se
echo-n"Nota nAr mst
rongnumbe r
"
f
i

OUTPUT:
[admin
@loca
lhos
tloops
]$s
har
mst
ron
g.s
h
Enteranumber:37
0
Arms t
ron
gNu mber

RESULT:
Th
usthes
hel
lpr
ogr
amt
ofi
ndt
hen
umb
eri
sAr
mst
ron
gorn
otha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

2
0
B—NUMBERREVERSE

AI
M:
Towr
i
teapr
ogr
amt
ofi
ndt
her
eve
rseo
fnumbe
r.

AL
GORITHM:
STEP1:St
artt
heprog r
am
STEP2:Readnum
STEP3:I
ni
ti
al
iz
erev_num=0
STEP4:I
ni
ti
al
iz
es i
gn=1/ /J
ustt
ohandl
ere
ver
sal
ofn
ega
ti
ven
umbe
rs
STEP5:I
fnum<0:
(a
)Mu l
ti
pl
yn umwi t
h-1
(
b)Assig
n-1t othevar
i
abl
esig
n.
STEP6:St
optheprogram

PROGRAM:
#Tor e v
e r
sean umberus
ingwhi
l
eloo
p
echo- n"Ente
ran umber:
"
readn
rd=0
wh i
l
e[$ n-gt0]
do
rem=èxpr$n%1 0`
rd=è
xpr$ r
d\ *10+$ r
em`
n=èx
pr$ n/1 0`
done
echo" Revers
e dnumberi
s$rd
"

OUTPUT:
[admin
@local
hos
tloops]
$shr
eve
rse
.sh
Enteranumber:23
4
Reversednumberi
s4 32

RESULT:
Thu
sthes
hel
lpr
ogr
amt
ofi
ndt
her
eve
rse
dnumbe
rha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sfu
ll
y.

2
1
C—F
IBONACCI
SERI
ES

AI
M:
Towr
i
teapr
ogr
amt
odi
spl
ayt
heF
ibon
acc
ise
ri
es.

ALGORITHM:
STEP1 :
Ini
t
ial
i
zen 1&n 2a s0&1.
STEP2 :
Entertheli
mitforFibonacci
.
STEP3 :
Ini
t
ial
i
zev ar
iabl
ea s0
STEP4 :
Pri
nttheF i
bona cci
se r
ie
sn 1andn2.
STEP
5:Whil
ethevarnumbe rislesserth
anli
m-2STEP6:
Calc
ulat
en3=n1+n 2
.
STEP7 :
Setn1=n 2andn 2=n3
STEP8 :
Incr
eme ntvarby1a n dpri
ntn2
STEP9 :
Stoptheprogra m.

PROGRAM:
#Fibona c
c iser
iesus
ingwhi
l
eloop
ec
ho- n"En t
ernumberoft
erms:"
r
eadn
ec
ho" Fi
bon acc
iSeri
es"
f
1=0f2 =1
ec
ho- n"$ f
1"
ec
ho- n"$ f2"
i
=2
whi
le[$ i-
lt$n]
do
f
3=èxpr$f1+$ f2`
ec
ho- n"$ f3"
f
1=$f2
f
2=$f3i=èxpr
$i
+1 ` done

OUTPUT:
[admin@l
ocal
hostl
oops
]$shf
i
bo.
sh
Enternumberofte
rms:8
Fib
o na
cciSe
ri
es
01123581 3

RESULT:
Th
usthes
hel
lpr
ogr
amt
ofi
ndF
ibo
nac
cis
eri
esh
asbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

2
2
D-
PRI
MENUMBER

AI
M:
Towr
i
teapr
ogr
amt
ofi
ndt
hen
umb
eri
spr
i
meorn
ot.

AL
GORITHM:
STEP1:Star
ttheprogra
m
STEP2:Readn umbern
STEP3:Setf=
0
STEP4:Fori
=2t on-
1
STEP5:I
fnmo d1=0then
STEP6:Setf=
1a ndb r
eak
STEP7:Loop
STEP8:I
ff=0then
Pr
i
nt“Thegi
venn
umbe
rispri
me”
El
se
Pr
i
nt“Thegi
venn
umbe
risnotpr
i
me”
STEP9:Stoptheprogra
m

PROGRAM:
#Primen umbe rusi
ngex
it
echo-n"Enterthenumber:"
rea
dn
i
=2
m=èxpr$n/2`
unt
il[$i-
gt$m]
do
q=è
x pr$
n%$ ìi
f
[$q- eq0]then
echo"NotaPr i
men umber"
exi
t
fi
i
=èx
pr$ i+1`
done
echo"Pri
men umb er"

OUTPUT:
[admin
@loc
alh
ostl
oops
]$s
hpr
i
me.
sh
Entert
henumber:
17
Pri
men umber

RESULT:
Thu
sthes
hel
lpr
ogr
amt
ofi
ndpr
i
men
umb
erha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sfu
ll
y.

2
3
E—F
ACTORI
ALVAL
UE

AI
M:
Tof
i
ndaf
act
ori
alofan
umbe
rus
ings
hel
lsc
ri
pt
.

ALGORITHM:
STEP1:re
adan umb er.
STEP2:I
ni
ti
ali
zefactas1.
STEP3:I
ni
ti
ali
zeIas1.
STEP4:Wh i
l
eI i
slesse
rthanoreq
ualtono
.
STEP5:Mult
ipl
ythevalueofI
andfac
tandass
ignt
ofa
cti
ncr
eme
ntt
hev
alueofI
by1.
STEP6:pri
ntth
eres ul
t
.
STEP7:Stoptheprogram.

PROGRAM:
#Fac t
ori
al v
alueusi
ngu nt
i
l
echo-n"En t
erapo si
t
ivenumb
er:
"
r
eadn
f
=1
unt
il
[$ n-lt1]
do
f
=è
xp r$f\*$ n`
n=è
xpr$ n-1 `
done
echo"Factori
alval
ue:$f"

OUTPUT:
[admin
@local
hos
tloops]
$shfac
t.
sh
En t
eraposi
ti
venumber:10F
actor
i
al
value:362
8800

RESULT:
Th
usthes
hel
lpr
ogr
amt
ofi
ndt
hef
act
ori
aln
umb
erha
sbe
ene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

2
4
F
—SUMOF1.
.
NNATURALNUMBERS

AI
M:
Towr
i
teapr
ogr
amt
ofi
nds
umofnn
atu
ral
numbe
rs.

AL
GORITHM:
STEP1:Sta
rttheprogr
am
STEP2:Readthev a
lueofn
.
STEP3:
.i=1 ,
SUM=0
STEP4:i
f(i>n)g oto7STEP
5:S=S+i
STEP6:i=i+1
STEP7:Dis
playtheval
ueofS
STEP8:Stoptheprogr
am

PROGRAM:
#Su m of1+2+3+..
.+Nnumber
s
echo-n"Ent
erNv al
ue:"
re
adn
sum=0
i
=1
unt
il
[$ i
-gt$n]do
sum=èx
pr$sum+$ ì
i
=èx
pr$i+1`
done
echo"Thesumo fnnumber
sis$
sum"

OUTPUT:
[
admin
@local
hostl
oops
]$s
hs u
m1t
on.
sh
Ente
rNv a
lue:26
Thesumofnn umbersi
s351

RESULT:
Thu
sthes
hel
lpr
ogr
amt
ofi
ndt
hes
umofnn
umbe
rsha
sbe
ene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

2
5
G—MATRI
XMULTI
PLI
CATI
ON

AI
M:
Towr
i
teapr
ogr
amt
ope
rfo
rmma
tri
xad
dit
i
onus
ings
hel
lpr
ogr
am.

ALGORITHM:
STEP1 :
Sta
rttheprogr
amSTEP
2:Gett
hema tr
i
xAa ndB
STEP3 :
Loopforrowsandcol
umns
STEP4 :
Cal
c ul
ateth
eresul
tmat
ri
xbyus
ingma
tri
xmul
t
ipl
i
cat
i
onSTEP
5:Di
spl
aytheresul
tmatr
ix
STEP6 :
Stoptheprogr
am

PROGRAM:
#i
ncl
ude<stdio.
h>
#i
ncl
ude<conio.
h>
voi
dma i
n()
{
i
nta[3]
[3],
b [
3][
3],
c[3]
[3]
,i
,j
;
cl
rscr
()
;
pri
nt
f(
"En t
ertheF i
rs
tma t
ri
x"
);
for
(i
=0;
i<3;
i++)for(
j=
0;j<
3;j
++)
scanf
("
%d ",
&a [
i]
[j
])
;
pri
nt
f(
"\nEn t
ertheSec ondmatri
x"
);
for
(i
=0;
i<3;
i++)
for
(j
=0;
j<3;j
++)
scanf
("
%d ",
&b [
i
][
j]
);
for
(i
=0;
i<3;
i++)
{
for
(j
=0;
j<3;j
++)
{c[i
]
[j
]=0;
for
(k=
0;k<3;k++)
{
c[
i]
[j
]=c[
i][
j
]+a [
i
][
k]*b[
k][
j];
}
}}
pri
nt
f(
"Ma tr
ixMulti
pl
icat
ionis:\
n\n"
);
for
(i
=0;
i<3;
i++)
{
for
(j
=0;
j<3;j
++)
{
pri
nt
f(
"\t%d" ,
c[i
]
[j
]);
}
pri
nt
f(
"\n")
;
}
get
ch();
}

2
6
OUTPUT:
EnterFi
rstMa t
ri
x
123
456
789
Ent
erSe condMatri
x
789
456
124
Matr
i
xMu l
t
ipl
i
cati
onis
:

18 24 33
54 69 90
90 114 147

RESULT:
Thu
sthepr
ogr
amt
ofi
ndt
hema
tri
xmu
lt
ipl
i
cat
i
onha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

2
7
EX.NO:
5 CPUSCHEDULI
NGAL
GORI
THMS
DATE:
A.ROUNDROBI
N

AI
M:
Towr
i
teapr
ogr
amt
osi
mul
at
eth
eRo
undRob
inCPUs
che
dul
i
nga
lgor
i
thm.

ALGORITHM:
STEP1:Getthenumbero fprocessandthei
rburstt
ime.
STEP2:I
nit
i
ali
zethear
rayf orRoundRob i
ncir
cul
arqu e
ueas‘0’
.
STEP3:Theb ur
stt
imeo fe achproce
s si
sdi
vi
d e
da ndthequot
i
entsarest
oredonther
oundr
obi
nar
ray.
STEP4:Accordi
ngtothea rra
yv a
luethewai
ti
ngti
mef oreac
hprocessandtheave
raget
imear
ecal
cul
at
eda
sli
ne
t
heo t
herschedul
i
ng.
STEP5:Thewa i
ti
ngti
mef o reac
hpr oces
sanda v
e r
ageti
mesaredis
play
ed.STEP
6:St
optheprogr
am

PROGRAM:
#include<stdio.
h>
#include<co ni
o.h>
vo i
dma i
n()
{
i
n tet[30]
,t
s ,
n,i
,
x =0,
tot
=0;
cha rpn [
10][10];
clrs
c r(
);
printf
("
En t
e rthen oofprocesses
:"
);
sc a
n f(
"%d",
&n );
print
f("
En t
ert heti
meq ua
ntum:"
);
sc a
n f(
"%d",
&t s);
for(
i=0
;i
<n;
i++)
{
print
f("
e n
terpr ocessname&e st
imat
edt
i
me:
"
);
sc a
n f(
"%s%d "
,pn[i
],
&et[
i
]);
}
print
f("
Th epr ocessesare:
")
;
for(
i=0;i
<n;
i++)
print
f("
proce ss%d: %s\n"
,i
+1,pn
[i
])
;
for(
i=0;i
<n;
i++)
tot=tot
+e t
[i
];
wh i
le(x!
=tot)
{
for(
i=0;i
<n;
i++)
{
i
f(et[i
]>
ts)
{
x=x+t s
;
print
f("
\n%s- >%d ",
pn[i
],
t
s);
et[i
]=et[
i]
-ts;
}
elseif(
(et[
i]
< =t
s)&&et[
i]
!
=0)
{
x=x+e t[
i]
;

2
8
pr
i
ntf
("
\n%s->%d",
pn[
i
],
et
[i
]
);e
t[i
]
=0;
}
}
}
pr
i
ntf
("
\nTot
alEs
ti
ma t
edTi
me:%d"
,x
);
ge
tch(
);
}

OUTPUT:
Ente
rthenoofprocesses:
2
Ente
rtheti
mequ an
tum:3
Ente
rtheproces
sn ame&e st
i
mat
edt
i
me:
p112
Ente
rtheproces
sn ame&e st
i
mat
edt
i
me:
p215
p1->3
p2->3
p1->3
p2->3
p1->3
p2->3
p1->3
p2->3
p2->3
Tota
lEst
imate
dTime :27

RESULT:
Thust
hepr
ogr
amf
orr
oun
dro
bins
che
dul
i
ngha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

2
9
B.SJ
F

AI
M:
Apr
ogr
amt
osi
mul
at
etheSJ
FCPUs
che
dul
i
nga
lgo
ri
thm.

ALGORITHM:
STEP1:Star
ttheprogr
am. Getthen umb ero fproce
ssesa ndthe
irbur
stt
ime .
STEP2:I
nit
i
ali
zethewa i
ti
ngti
mef orprocess1a s0.
STEP3:Theprocessesarestoreda c c
ordi
ngt othei
rburstt
ime.STEP
4:Thewai
ti
ngti
mef ortheproce s
s esa r
eca l
culat
edaf ol
l
ows :
f
or(
i=2;
i
<=n;
i++)
.wt.
p[i
]
= p[i
=1]+b t
.
p[i
-1].
STEP5:Thewa i
ti
ngti
meofa llthepr ocess
e ss umme dandthentheaver
ag et
imei
sca
lcul
at
ed.
STEP6:Thewa i
ti
ngti
meofe a chpr ocessesa ndaverageti
mea r
ed i
spl
ayed.
STEP7:Stoptheprogr
am.

PROGRAM:
#incl
ude<stdi
o.
h>
#inc
lude<conio
.h>
#inc
lude<str
ing.
h>
voi
dma i
n()
{
i
ntet[20]
,at
[10],
n,
i
,j
,
temp,s
t[10]
,f
t[
10]
,wt[
10]
,
ta[
10]
;in
t
tot
wt=0,t
otta=0;
fl
oatawt,a
ta;
charpn[10][
10],
t[
10];
cl
rscr(
);
pri
ntf
("
En t
erthenumbe rofproces
s:"
);
scanf(
"%d",
&n )
;
for
(i
=0;i
<n;
i++)
{
pri
ntf
("
En t
erprocessname ,
arri
val
ti
me&e xecut
i
ontime
:"
);
fl
usha
ll
()
;
scanf(
"%s%d %d",
pn[
i]
,
&a t
[i
]
,&et[
i
])
;
}
for
(i
=0;i
<n;
i
++)
for
(j
=0;j
<n;
j++)
{
i
f(et
[i
]<et
[j
])
{
temp=at[i
]
;
at[
i]
=at[
j]
;
at[
j]
=temp;
temp=e t
[i
]
;
et[
i]
=et[
j]
;
et[
j]
=temp;
str
cpy(t
,pn[
i]
);
str
cpy(pn[
i],
pn[j
]
);
str
cpy(pn[
j],
t)
;
}
}
for
(i
=0;i
<n;
i++)
{

3
0
i
f(i
==0)
st[
i]=
a t
[i
]
;
elses t
[i
]
= f
t[
i
-1];
wt[i
]=st[
i
]-at
[i
];
ft[
i
]=st[
i]
+et[
i]
;
ta[
i]=
ft[
i
]-at
[i
];
totwt+=wt[i
]
;
tott
a+=ta[i
];
}
awt =
(fl
oat)
tot
wt/n;
ata=(f
loat
)t
ott
a/n;
pri
n t
f(
"\nPname\tarr
i
val
ti
me \t
exe
cuti
ont
ime\t
wait
i
ngt
ime\t
ta
ti
me "
);
for(
i=0;
i<
n ;
i
++)
pri
n t
f(
"\n%s\t
%5d \
t\t
%5 d\
t\t
%5d\t
\t
%5 d"
,
pn[i
]
,a
t[
i]
,
et[
i
],
wt[
i
],
ta
[i
])
;
pri
n t
f(
"\nAveragewa i
ti
ngti
meis:
%f"
,awt)
;
pri
n t
f(
"\nAverageturn
aroundt
imeis
:%f"
,
ata)
;
getch();
}

OUTPUT:
Entert
henumberofproc
esses
:3
Entert
hePr
ocessNa me,Ar
ri
valTi
me&BurstTi
me:146
Entert
hePr
ocessNa me,Ar
ri
valTi
me&BurstTi
me:2515
Entert
hePr
ocessNa me,Ar
ri
valTi
me&BurstTi
me:3611
Pna
me a r
ri
val
t
ime e xec
uti
onti
me wa
it
in
gtimeta
ti
me
1 4 6 0 6
3 6 11 4 15
2 5 15 16 31

Av
era
geWai
ti
ngTi
me:
6.66
67
Av
era
geTur
nArou
ndTi
me :
17.
333
3

RESULT:
Thu
sthepr
ogr
amf
orSJ
Fsc
hed
uli
ngh
asbe
ene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

3
1
C.F
CFS

AI
M:
Apr
ogr
amt
osi
mul
at
etheF
CFSCPUs
che
dul
i
nga
lgor
i
thm

ALGORITHM:
STEP1 :
Star
ttheprogram.
STEP2 :
Getthenumbe rofprocesse sandthei
rbur
stt
ime.
STEP3 :
Ini
t
ial
i
zethewa i
ti
n gti
mef orprocess1and0.
STEP4 :
Thewa i
ti
ngti
mef ort
heo therproces
sesarecal
cul
at
edasfol
l
ows:
f
or(
i=2
;i
<=n;
i
++),
wt.
p[i
]=p[i
-1]+b
t.
p[i
-1].
STEP5 :
Thewa i
ti
ngti
meofa l
lthepr oc
es s
esissummedthenaver
ageval
ueti
mei
sca
lcu
lat
ed.
STEP6 :
Thewa i
ti
ngti
meofe achpr ocessandave
rageti
mesaredi
spl
aye
d .
STEP7 :
Stoptheprogram.

PROGRAM:
#i
nclude<stdi
o.
h>
#i
nclude<coni
o.
h>
voi
dma i
n()
{
charpn[10][
10];
i
ntarr[
10],
b ur
[10]
,
star
[10],
f
ini
sh[
10 ]
,
tat
[10]
,
wt[10
],
i,
n;i
nt
tot
wt=0,t
ottat
=0;
cl
rscr(
);
pri
nt
f("
En t
erthenumbe rofprocesses:
"
);
scanf(
"%d",
&n);
for
(i
=0;i
<n;
i++)
{
pri
nt
f("
En t
ertheProcessNa me,Arri
val
Time&Bu rstTime:
"
);
scanf(
"%s%d%d "
,&pn[
i]
,&arr
[i
],
&bur[
i]
);
}
for
(i
=0;i
<n;
i++)
{
i
f(
i==0)
{
st
ar[i
]=ar
r[i
];
wt[i
]=s
tar
[i
]
-ar
r[
i];
fi
ni
sh[i
]=st
ar[
i]
+bur[
i]
;
ta
t[i
]
= f
i
n i
sh[i
]
-arr
[i
];
}
el
se
{
st
ar[i
]=f
ini
sh[i
-1]
;
wt[
i]
= s
tar[
i]
-ar
r[i
]
;
f
ini
sh[i
]=st
ar[
i]
+bur[
i]
;
ta
t[i
]
= f
i
n i
sh[i
]
-arr
[i
];
}
}
pri
ntf
("
\nPNa me Ar rt
i
me Bu rt
ime St ar
t TATF i
nish"
);
for
(i
=0;i
<n;
i++)
{
pri
ntf
("
\n%s \t
%6d \
t\t
%6d \
t%6d\t%6d\t
%6 d"
,
pn[i
]
,ar
r[i
]
,bur
[i
]
,sta
r[i
]
,t
at[
i
],
fi
ni
sh[
i
])
;

3
2
to
twt+=wt[
i]
;
tot
tat
+=tat
[i
]
;
}
pri
ntf
("
\nAvera
geWai
ti
ngti
me:%f
",
(f
lo
at)
totwt
/n)
;pr
i
ntf
("
\nAv
era
ge
TurnAroundTime
:%f
",
(
fl
oat
)t
ott
at/
n);ge
tch()
;
}

OUTPUT:
Entert
henumbe rofproces
ses:3
Entert
hePr oces
sNa me ,Arr
i
valTi
me&Bu r
stTi
me:123
Entert
h eProces
sNa me ,Arr
i
valTi
me&Bu r
stTi
me:256
Entert
h eProces
sNa me ,Arr
i
valTi
me&Bu r
stTi
me:367
PNa meArrt
i
meBu rt
i
meSt ar
tTATF i
ni
sh
1 2 3 2 3 5
2 5 6 5 6 4
3 6 7 6 7 10
Av e
rageWaiti
ngTime:3.
333
Av e
rageTur
nAr oundTime:7.
000

RESULT:
Thu
sthepr
ogr
amf
orF
CFSha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sfu
ll
y.

3
3
D.PRI
ORI
TY

AI
M:
Apr
ogr
amt
osi
mul
at
ethepr
i
ori
t
yCPUs
che
dul
i
nga
lgor
i
thm

ALGORITHM:
STEP1:Star
ttheprogr
am.
STEP2:Readb ur
stti
me,wa i
t
ingti
me ,
tur
nthearoun
dti
mea n dpri
ori
ty
.
STEP3:I
nit
i
ali
zethewa i
t
ingti
mef orprocess1and0.
STEP4:Basedupo nthepri
ori
typroc es
sa r
earr
anged.
STEP5:Thewa i
ti
ngti
mef orot
h e
rpr ocesse
sa r
ecal
cul
ate
db asedo npri
or
it
y.
STEP6:Thewa i
ti
ngti
meofa l
lthepr ocess
esissummeda ndthentheavera
gewait
i
ngtimei
scal
cul
at
ed.
STEP7:Thewa i
ti
ngti
meofe achpr ocessandaver
agewait
i
n gti
mea redi
spl
ayedbase
donthepr
ior
i
ty.
STEP
8:St
optheprogr
am.

PROGRAM:
#inc l
ude <
std i
o.
h>
#includ e
<co nio
.h>
#includ e
<string.
h>
voidma i
n()
{
i
nte t[20],
at
[1 0]
,n,
i
,
j,
temp,
p[10]
,st
[10]
,
ft
[10]
,
wt[10
],
ta
[10
];i
nt
totwt =0,
tot
ta =0;
fl
oa tawt ,
at
a ;
cha rpn [
10][10],
t[
10];
cl
rsc r(
);
printf(
"Ent
e rthenumbe rofproces
s:"
);
scan f(
"%d "
,&n )
;
for(
i= 0;
i<
n;i
++)
{
printf(
"Ent
e rprocessname ,
ar
riv
alt
i
me ,
execu
ti
onti
me&pr i
or
it
y:
")
;
fl
ush all
()
;
scan f(
"%s%d %d%d",
pn[i
],
&at
[i
],
&et[
i]
,
&p[i
])
;
}
for(
i= 0
;i
<n;i
++)
for(
j= 0;
j<n
;j
++)
{
i
f(p[i
]<p[j]
)
{
temp= p[
i]
;
p[i
]= p[
j];
p[j]
= temp;
temp= at
[i
];
at[i
]=at[j
];
at[j
]= t
emp;
temp= et
[i
];
et[i
]=et[j
];
et[j
]= t
emp;
strcp y
(t,
pn[i
]);
strcpy(pn[i
],pn[j
]
);
strcpy(pn[j
],t)
;
}

3
4
}
for(
i
=0;i
<n ;
i
++)
{
i
f(i
==0)
{
st[
i]
=at[
i
];
wt[i
]=s
t[
i]-at
[i
]
;
ft[
i
]=st
[i
]+et[
i]
;
ta[
i]
=ft
[i
]-at
[i
];
}
else
{
st[
i]
=ft
[i
-1];
wt[i
]=s
t[i
]-at
[i
];
ft[
i
]=st
[i
]+et[
i]
;
ta[
i]
=ft
[i
]-at
[i
];
}
tot
wt+=wt [
i]
;
tott
a+=t
a [i
]
;
}
awt=(f
l
oa t)
tot
wt/n;
ata=(
fl
oat)t
ott
a/n;
pri
ntf
("
\n Pname\tarr
i
val
ti
me \t
exe
cuti
ont
ime\t
pri
ori
t
y\t
wa i
t
ingti
me \
tt
ati
me");
for
(i
=0;
i<
n;i
++)
pri
ntf
("
\n%s \t
%5d \
t\t
%5d\t\
t%5d\
t\t
%5d\t
\t
%5 d"
,
pn[i
]
,at
[i
]
,et
[i
]
,p[
i]
,wt[
i
],
ta
[i
])
;pri
nt
f(
"\n
Av e
rage
wa i
ti
ngtimeis:
%f",
awt);
pri
ntf
("
\n Averagetur
naroundt
i
meis:
%f",
at
a);
getch(
);
}

OUTPUT:
Entert
henumbe rofpr
oce s
ses:3
Entert
h eProcessName ,Arr
iva
lTime,e
xecut
ionti
me&prior
i
ty:1231
Entert
h eProcessName ,Arr
iva
lTime,e
xecut
ionti
me&prior
i
ty:2452
Entert
heProcessName ,Arr
iv
alTi
me ,
exe
cuti
onti
me&pri
ori
t
y:3563
Pna
me a rri
val
ti
me e xe c
uti
onti
me pr i
or
it
y wa it
i
ngt
i
me t at
i
me
1 2 3 1 0 3
2 4 5 2 1 6
3 5 6 3 5 11
Av e
rageWa i
ti
ngTime:
2 .
0000Av er
age
TurnAroundTime:6.
6667

RESULT:
Thu
sthepr
ogr
amf
orpr
i
ori
t
ysc
hedu
li
ngh
asb
eene
val
uat
eda
nde
xec
ute
dsuc
ces
sfu
ll
y.

3
5
EX.NO:
6 I
MPL
EMENTSEMAPHORES
DATE:

AI
M:
Toi
mpl
eme
ntpr
odu
cer
/co
nsume
rpr
obl
emu
sin
gse
maphor
e.

ALGORITHM:
STEP1 :
Star
ttheprogram
STEP2 :
Decla
revari
ablef orproducer&c o
nsumeraspthrea
d-t
-t
idpr
oduceti
dcon
sume
.
STEP3 :
Decla
reas tr
uctu retoadditems,semaphor
evari
abl
esetasst
ruct
.
STEP4 :
Readn umbero fitemstob eproducedandconsumed.
STEP5 :
Decla
rea n
dd efi
n es emaphoref
u nct
ionf
orcr
eati
onanddest
roy.
STEP6 :
Defi
neproducerf uncti
on.
STEP7 :
Defi
neco n
sume rfuncti
on.
STEP
8:Cal
lpr
oducerandc onsu me r
.STEP9 :
Stopt
hee x
ecuti
on.

PROGRAM:
#i
n c l
ude <stdi
o.h>
#i
n c l
ude<s ema phore.
h>
#i
n c l
ude <pthread.
h>
#d efi
n eNBUF F1 0
i
ntn it
e ms;
st
r uct{
i
ntbuf f
[NBUF F ]
;
sem_ tmu tex,
n empty,nst
ored;
}sha r
e d;
void* prod uce(v
o i
d*);voi
d
*co nsume (voi
d *
);
i
ntma in(i
nt
ar
g c ,
cha r
**a r
gv){pthread_t
ti
d_ produc e,
ti
d_con s
u me ;
i
f(
a rgc !
=2){print
f("
usage :
fi
l
en a
me <n i
t
ems >")
;return0;
}
pri
n tf
("\n\nproduce r
_con s
u me rprobl
emu si
ngse
ma ph
ore\
n")
;
pri
n tf
(" \n
")
;
ni
te ms =atoi(
argv[1])
;
sem_ i
n i
t
(&s hared.
mu tex,
0,1);
sem_ i
nit
(&s hare
d .
nempt y,
0,
NBUF F);
sem_ i
n i
t
(&s hared.
nstored,
0,0);
pthre ad_setconcurrency(2)
;
pthre ad_create(
&tid_produce,NUL L,
pro
duce,
NULL);
pt
h rea d_create(
&ti
d _
c onsume ,
NUL L,
consume,
NULL)
;
pthre ad_j
oin (
ti
d_produc e,
NUL L);
pth r
e ad_j
o i
n (
ti
d_consu me,NUL L);
sem_ destroy(&shared.
mut ex);sem_destr
oy(
&shar
ed.
nempt
y)
;
sem_ destroy(&shared.
n st
ored);
}
void* produ ce(v
o i
d
*arg )
{inti;

3
6
for
(i
=0;i
<ni
te ms;i
++)
{
sem_wa it
(&sh ar
ed.
nempty);
sem_wa it
(&s har
ed.mutex
);
shar
ed .
buff[i
%NBUF F]=i
;
pri
nt
f("
\tprodu cer "
);
pri
nt
f(
"bu f
f[%d ]
=%d\n\n
",
i,
shar
ed.
buf
f[
i%NBUFF])
;
sem_pos t
(&s hared.
mutex)
;sem_post(
&shar
ed.
nstor
ed)
;
sl
eep(3);
}
ret
urnNUL L;
}
voi
d*c onsu me(voi
d
*ar
g){inti
;
for
(i
=0;i
<ni
te ms ;
i
++){
sem_wa it
(&s har
ed.ns
tore
d);
sem_wa it
(&s har
ed.mutex
);
pri
nt
f("
\tcon sume r ")
;
pri
nt
f("
bu f
f[%d ]
=%d\n\n\
n",
i
,shar
ed.
buff
[i
%NBUFF])
;
sem_pos t
(&s hared.
mutex)
;sem_post(
&shar
ed.
nempty)
;
sl
eep(3);
}
ret
urnNUL L;
}

OUTPUT:
Ente
rtheval
ueo fn=
4
Ente
rthei
tem= 1Ente
r
thei
tem=2Enterthe
it
em=3Entert
h e
it
em=5Co n
s umer
it
em=1Co n
s umer
it
em=2Cons umer
it
em=3Cons umer
it
em=5

RESULT:
Thust
hepr
oduc
erc
ons
ume
rpr
ogr
amwa
sex
ecut
eda
ndv
eri
f
ieds
ucc
ess
ful
l
y

3
7
EX.
NO:
7 I
MPL
EMENTATI
ONOFSHAREDMEMORYANDI
PCDATE:

AI
M:
Toi
mpl
eme
ntI
PCi
nUNI
X.

ALGORITHM:
STEP1:St
artt
heprog ram.
STEP2:Ge
tthen umbe rofsegment
s.
STEP3:Ge
ttheb aseadd r
essandleng
thforeachsegme n
ts.
STEP4:Ge
tthelogi
c aladdre
ss.
STEP5:Checkwheth e
rt h
es eg
me n
tnumbe ri
swit
hi
nthelimi
t,i
fno
tdi
spl
a yt
heerr
orme
ssa
ge.
STEP6:
Checkwhet
hertheb yt
er ef
erenc
eiswit
hi
nt hel
i
mit
,ifnotdi
spl
aythee
rrormess
age.
STEP7:St
opthepro gram.

PROGRAM:
#i
nclude<stdi
o.
h>
#i
nclude<sys/
types
.h>
i
ntma i
n (
)
{
i
ntfd[2]
;
pi
d_pid :
charbuff[
30];
pi
pe(fd);
pi
d=fork(
);
i
f(
pi
d ==0)
{
Cl
os e(f
d[0]
);
Pri
ntf
(“cl
ie
ntiswri
ti
ngPI PE!
!!
\n
”);
Wri
te(fd[
1],
”ALLISWEL L ”
,s
izeo
f(b
uff
))
;
}
el
se
{
Cl
os e(f
d[1]
);
Pri
ntf
(“par
entisrea
dingreadi
ngthePIPE!
!
!
\n”
);
Read(fd[
0],
buff
,s
izeof
(buff
))
;
Pri
ntf
(“%s”,
buff
);
}
}

OUTPUT:
[s
tuden
t@loca
lho
ststudent
]$c
ce x
2 7
.c
[s
tudent@l
ocal
hoststude
nt]
$./a
.out
Pare
ntisre
adi
ngreadin
gthePIPE!
!!
Pare
ntisre
adi
ngreadin
gthePIPE!
!!

RESULT:
Thust
hepr
ogr
amt
oimpl
eme
ntI
PCwa
sex
ecut
eds
ucc
ess
ful
l
y.

3
8
EX.
NO:
8 BANKERSALGORI
THMF
ORDEADLOCKAVOI
DANCEDATE:

AI
M:
Apr
ogr
amt
osi
mul
at
etheBa
nke
rsAl
gor
i
thmf
orDe
adl
ockAv
oida
nce
.

AL
GORITHM:
STEP1:Startt
hepr ogr
am
STEP2:En t
erthenumbe rofpro
cessesSTEP
3:En
terthenumb erofresour
ceclas
s e
sSTEP
4:En
tertheall
ocat
edresources
STEP4:F i
ndtheprocesswh i
chareinbloc
kedorr
unn
ings
tat
e
STEP5 :
Stopthepr o
gram

PROGRAM:
#i
n c
lude<stdi
o .
h>
st
ructfi
le
{
i
ntall
[10];
int
ma x[
10];i
nt
need[1
0 ];
int
fl
ag;
};
voi
dma i
n()
{
st
ructfi
lef[10];
i
ntfl
;
i
nti,j
,k,p,b ,
n ,r
,g,cnt=0,i
d, ne
wr;int
avai
l[
10],
se q[
10] ;
cl
rscr
();
pri
ntf
("
En t
e rnumb erofproc esses--")
;
scanf
("
%d ",
&n );
pri
ntf
("
En t
e rnumb erofreso urce
s- -"
);
scanf
("
%d" ,
&r )
;
for
(i
=0;
i<n;
i++)
{
pri
ntf
("
En t
e rdetai
lsforP%d" ,
i)
;
pri
ntf
("
\nEn terall
ocati
on\t--\t"
);
for
(j
=0;j
<r;
j++)s canf
("%d",
&f[i]
.
all
[
j]
);
pri
ntf
("
En t
e rMa x\t
\t--\t
");
for
(j
=0;j
<r;
j++)
scanf
("
%d ",
&f[i]
.max[j
])
;f[
i]
.f
lag=0;
}
pri
ntf
("
\nEn te
rAv ail
abl
eRe s ourc
es\t--\t
")
;
for
(i
=0;
i<r;
i
++)
scanf
("
%d" ,
&a vail
[i
]
);
pri
ntf
("
\nEn te
rNe wRe questDe t
ail
s--")
;
pri
ntf
("
\nEn terpid\t--\t
");scanf(
"%d",
&i
d);
pri
ntf
("
En t
e rRe questfo
rRe sour
ces\t--\t
")
;
for
(i
=0;
i<r;
i
++)
{
scanf
("
%d" ,
&n ewr )
;
f[
i
d ]
.
all
[
i]+=n e wr;
avai
l[
i
]=avail
[i
]-n ewr;
}

3
9
for
(i
=0;i
< n;
i
++)
{
for
(j
=0 ;
j<r;
j
++)
{
f
[i
].
need [j
]=f
[i
].
ma x[
j
]-f
[i
]
.a
ll
[j
]
;
i
f(
f[
i].
nee d[
j]<
0)
f[
i
].
nee d[j
]=0;
}
}
cnt
= 0;
fl
=0;
whil
e(cn t
!
= n)
{g=
0;
for
(j
=0 ;
j<n;
j++)
{
i
f(
f[
j].
f
lag ==0)
{b=
0;
for
(p=0 ;
p<r;
p++)
{
i
f(
avail
[p]>=f
[j
].
need[p]
)b=b+1;
el
se
b=b-1;
}
i
f(
b= =
r)
{
pri
ntf
("\nP%di svis
it
ed",
j
);
seq[f
l
++] =j;
f[
j
].
fl
ag= 1;for(
k=0;k
<r;
k++)
avai
l[
k]=avail
[
k]+f[
j]
.
all
[
k];
cnt
= c
n t+1;
pri
ntf
("("
);
for
(k=0;k<r;
k++)
pri
ntf
("
%3 d "
,av
a i
l
[k]
);
pri
ntf
("
)");
g=1;
}
}
}
i
f(
g= =
0)
{
pri
ntf
("\nREQUESTNOTGRANTED- -DEADLOCKOCCURRED"
);
pri
ntf
("\nSYSTEMI SINUNSAF ESTATE");g
otoy;
}
}
pri
ntf
("\nSYSTEMI SINSAF ESTATE");
pri
ntf
("\nTheSa feSequenceis--("
);
for
(i
=0;i
< f
l;
i
++)
pri
ntf
("P%d" ,s
e q[
i]
);
pri
ntf
(")"
);pri
ntf
("
\nProces
s\t\t
All
ocat
i
on\t\
tMax\
t\t
\t
Nee
d\n
");
for
(i
=0;i
< n;
i
++)
{
pri
ntf
("P%d \t
",
i)
;for(
j=
0;j
<r;
j
++)
pri
ntf
("
%6 d "
,f
[i
]
.al
l
[j]
);
for
(j
=0 ;
j<r;
j
++)

4
0
pri
nt
f(
"%6d",
f[
i
].
max[j
]
);
for
(j
=0;
j<
r;
j++)
pri
nt
f(
"%6d",
f
[i
].
nee
d[j
])
;
pri
nt
f(
"\n
");
}
get
ch()
;
}

I
NPUT
Ent
ernumbe rofproc
esses – 5
Ent
ernumbe rofre
sourc
es -
- 3
Ent
erdet
ai
lsforP0
Ent
eral
l
oca
tion -
- 0 1 0
En
terMax -
- 7 5 3

,
Enterdet
ail
sforP1
Ent
erall
oca
ti
on -
- 2 0 0
En
terMa x -
- 3 2 2

Ent
erdet
ai
lsforP2
Ent
eral
l
oca
tion -
- 3 0 2
En
terMax -
- 9 0 2

Ent
erdet
ai
lsforP3
Ent
eral
l
oca
tion -
- 2 1 1
En
terMax -
- 2 2 2

Ent
erdet
ai
lsforP4
Ent
eral
l
oca
tion -
- 0 0 2
En
terMax -
- 4 3 3

En
terAva
il
abl
eRe so
urce
s-- 3 3 2
En
terNewRequestDet
ail
s--
En
terpi
d - -1
En
terReque
stforResour
ces–1 0 2

OUTPUT
P1isvi
si
te
d(532 )
P3isvi
si
te
d(743 )
P4isvi
si
te
d(745 )
P0isvi
si
te
d(755 )
P2isvi
si
te
d(1057 )
SYSTEMISINSAFESTATE
TheSaf
eSe que
ncei
s--(
P1P3P4P0P2)

Pr
oces
s Al
loc
ati
on Ma
x Ne
ed
P0 0 1 0 7 5 3 7 4 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1

RESULT:
Thu
sthepr
ogr
amd
ead
loc
kav
oid
anc
eus
ingBa
nke
r’
sal
gor
i
thmha
sbe
ene
val
uat
eda
nde
xec
ute
dsu
cce
ssf
ul
ly
.

4
1
EX.
NO:
9 SI
MULATEF
ORDEADL
OCKDETECTI
ONDATE:

AI
M:
Towr
i
teapr
ogr
amt
osi
mul
at
eBa
nke
rsAl
gor
i
thmf
orDe
adl
ockDe
tec
ti
on.

ALGORITHM:
STEP1:Sta
rtt
h eprogr
am
STEP2:Decl
arethevar
iab
lesa
ndg etn
u mb
erofproces
ses
,res
ou r
cea cc
essanda
ll
ocat
e
STEP3:Decl
aretheproces
sma ki
ngnewreque
sta n
dproc
essblockrunni
ng
STEP4:Defi
neall
ocat
i
onme moryspacean
dde a
dlockdeal
l
ocat
ere s
o ur
ceoft
heproc
essSTEP
5:St
optheexecut
ion

PROGRAM:
#i
nclude < stdi
o.
h>
#i
nclud e< coni
o.
h>
voi
dma i
n()
{
i
ntfoun d,
f
lag ,
l
,
p[4]
[5],
tp,
tr
,c
[4][
5],
i
,j
,
k=1,
m[5]
,r
[5]
,
a[5]
,
temp[5
],
sum=0;cl
rs
cr(
);
pri
nt
f(
"En
tert
ota
l
n
oo fpr ocesses"
);
scanf(
"%d "
,&tp);
pri
nt
f("Entertota
lnoofr esourc
es")
;
scanf(
"%d "
,&tr)
;
pri
nt
f("Enterclai
m( Ma x
.Nee d
)ma t
ri
x\n
");
for
(i
=1 ;
i<
=tp;i
++)
{
pri
nt
f("process%d :
\n",
i)
;
for
(j
=1 ;
j<=t
r;j
++)
scanf(
"%d "
,&c[i
][
j]
);
}
pri
nt
f("Ent
e rall
ocat
ionma t
ri
x \
n")
;
for
(i
=1 ;
i<
=tp;i
++)
{
pri
nt
f("process%d :
\n",
i)
;
for
(j
=1 ;
j<=t
r;j
++)
scanf(
"%d "
,&p[i
][
j]
);
}
pri
nt
f("Ent
e rresour
c evect
or(Totalr
esour
ces)
:\
n")
;
for
(i
=1 ;
i<
=tr;
i++)
{
scanf(
"%d "
,&r[i
]
);
}
pri
nt
f("Ent
e ravai
lab
il
it
yv ec
tor(ava
il
abl
eresour
ces)
:
\n")
;f
or(
i=
1;i
<=t
r;
i
++)
{
scanf(
"%d",&a[i
])
;
te
mp[ i]
=a[i
];
}
for
(i
=1 ;
i<
=tp;i
++)
{
sum= 0;
for
(j
=1 ;
j<=t
r;j
++)
{
sum+= p[i
][
j];
}
i
f(
sum= =0)
{
m[k]
= i
;

4
2
k++;
}
}
for
(i
=1;i
<=t
p;i
++)
{
for
(l
=1;
l<k;
l
++)
i
f(
i!
=m[l]
)
{
fl
ag=1;
for
(j
=1;j
<=tr;
j
++)
i
f(
c [
i
][j
]
< t
emp[ j
])
{
fl
ag=0;
break;
}}
i
f(
fl
ag =
= 1)
{
m[k]=i
;
k++;
for
(j
=1;j
<=tr;
j
++)
temp[j
]+=p[i
][j
]
;
}}
pri
ntf
("
d ea
d l
ockcau
sin
gpr
oce
sse
sar
e:
")
;
for
(j
=1;j
<=tp;
j++)
{
found=0;
for
(i
=1;
i<k;
i
++)
{
i
f(
j==m[i]
)
found=1;
}
i
f(
found =
=0 )
pri
ntf
("
%d \t
",
j)
;
}
getch(
);
}

OUTPUT:
Ente
rtot
alno.ofprocess
es:4
Ente
rtot
alno.ofresour
ces:5
Ente
rcl
ai
m( Ma x.Need)matr
ix:
01001
00101
00001
10101
Ente
ral
loc
ationma t
ri
x:
10110
11000
00010
00000
Ente
rres
ourcev ect
or(Tota
lresour
ces)
:
21121
Ente
ravai
l
abil
i
tyve c
tor(a
vai
labl
eresou
rces
):
00001
Deadl
ockcausingprocesse
sa r
e: 23

RESULT:
Th
ust
hepr
ogr
amf
ord
ead
loc
kde
tec
ti
onha
sbe
ene
val
uat
eda
nde
xec
ute
dsuc
ces
sfu
ll
y.

4
3
EX.
NO:
10 I
MPL
EMENTTHREADI
NG&SYNCHRONI
ZATI
ONAPPLI
CATI
ONSDATE:

AI
M:
Towr
i
teaCpr
ogr
amt
oimpl
eme
ntThr
ead
ing&Sy
nchr
oni
zat
i
on

ALGORITHM:
St
ep1:St
artt
hePr ogram
St
ep2:Obtai
ntherequir
edd at
athroughchara
ndindat
aty
pes
.
St
ep3:Ent
erthefi
len
a me,in
dexb l
ock.
St
ep4:Pr
intt
hefil
ena meindexl
o o
p.
St
ep5:Fi
l
eisall
ocate
dt otheunusedindexbl
ocks
St
ep6:Thi
sisall
ocat
e dtotheunusedli
nkedal
l
ocat
io
n.
St
ep7:St
opthee xecuti
on

PROGRAM:
#i
nclude<st
dio.
h>
#i
nclude<st
ri
ng .
h>
#i
nclu
de <
p t
hread.
h>
#i
nclude<st
dli
b.h>
#i
nclude<uni
std.
h>
pt
h r
ead_tti
d[2];
i
ntcounter;
voi
d*doSome Thi
ng(voi
d*arg)
{unsignedlongi=0 ;
counter+=1 ;
pri
nt
f("
\nJ ob%ds tar
ted\n
",count
er)
;
for
(i
=0;i<
(0xFFFFFFFF);
i
++);
pri
nt
f("
\nJ ob%df i
nis
hed\n",
counter
);
ret
urnNUL L ;
}
i
ntma i
n(voi
d)
{
i
nti=0; i
nt
err
;wh i
le(
i<
2)
{
err=pthread_crea
te(
&(ti
d[i
]
),NULL,&doSome Thi
ng,NUL
L);
if(
err
!
=0)
pri
ntf
("\ncan
'tcreat
et hrea
d: [
%s]"
,s t
rer
ror(
err
))
;
i
++; }
pthr
ead _
joi
n(ti
d[
0], NUL L)
;
pthr
ead _
joi
n(ti
d[
1], NUL L)
;
ret
urn0;}

OUTPUT:
Job1sta
rte
d
Job2sta
rte
d
Job2fi
ni
shed
Job2fi
ni
shed

RESULT:
Th
usthei
mpl
eme
nta
ti
ono
fth
rea
din
g&s
ync
hro
niz
ati
ona
ppl
i
cat
i
onsha
sbe
end
ones
ucc
ess
ful
l
y.

4
4
EX.
NO:
11 CONTI
GUOUSMEMORYALL
OCATIONTECHNI
QUESDATE:
a
)Wors
t-f
i
t b)Be
st-
fi
t c
)Fi
r
st-
fi
t
AI
M:
Towrit
eaCprogramtosi
mul
at
ethef
ol
lowi
ngc
ont
i
guousme
mor
yal
l
oca
ti
ont
echn
ique
s
a
)Wor
st-
fi
tb)Be
st-
fi
tc)Fi
r
st-
fi
t

DESCRI PTION
On eo fthes impl
e stme t
hodsforme mor yall
ocat
i
onistod i
vi
deme moryintoseveralf
i
xed-si
zedpa rti
t
ions.Each
part
it
ionma yc ontai
ne xact
lyonepr ocess.Inthi
smu lt
i
ple-
part
i
ti
onme thod,whe napa rt
it
i
oni sfree
,apr ocessis
sele
ctedf r
o mt hei nputqu eueandi sloade dint
othef r
eepa r
ti
ti
on.Whe nthepr ocessterminat
es,thepa rti
ti
on
become sa vail
ab l
efora n
otherprocess.Theope rat
i
ngs ys
temk eepsata bl
eindi
cat
ingwhichpa rt
so fme morya re
avai
labl
ea ndwhi char eoccupi
ed.Fi
n a
ll
y,wh enaprocessarr
iv
esandn eedsme mory,
ame morysecti
onlargee n
o ugh
forthi
sproc essi sprovi
ded.Whe niti
st i
met oloadorswa paprocessint
oma inme mory,andifther
eismo r
et han
onefreeb l
oc kofme mo ryofsuff
i
cientsi
ze,thentheoperat
i
ngs y
stemmu stdecidewhichfre
eblocktoa l
locate
.Be st
-
fi
tstr
ategyc hoo sest
h eblockth
atisclosesti
ns i
zetothereques
t.F
irs
t-f
i
tchoosesthefi
rstavai
l
ab l
eblockthati
slarge
enough.Wo rst-
fitchoosesthelar
gesta v
ail
abl
eblock.

PROGRAM
WORST- F I
T
#incl
ud e<st
dio.
h >
#incl
ude< c
o ni
o.h>
#de f
inema x25
voidma i
n (
)
{
i
n tf
rag[max ]
,
b [
ma x]
,f
[ma x]
,i
,j
,n
b,nf
,
temp;st
ati
cint
bf[max],
ff
[ma x];
clrs
cr()
;
print
f(
"\n\t
Me mor yMa nage mentScheme-F i
r
stFit
")
;
print
f(
"\nEnterthen umbe rofblock
s:"
);
scanf
("
%d "
,
&nb);
print
f(
"Enterthen umbe roffi
les:
"
);
sc a
n f
("
%d "
,&nf);
print
f(
"\nEnterthes i
zeo ftheblock
s:-
\n"
);
for(
i=1;
i<
= n
b ;
i
++)
{
print
f(
"Block%d: "
,
i)
;
sc a
n f
("
%d "
,&b [
i
]);
}
print
f(
"Enterthes i
zeo fthefil
es:
-\n"
);
for(
i=1;
i<
= n
f;i
++)
{
print
f(
"Fi
le%d :
",
i)
;
sc a
n f
("
%d "
,&f[i
]
);
}
for(
i=1;
i<
= n
f;i
++)
{
for(
j=1;
j<=nb;
j++)
{
i
f(bf[
j]
!=1)
{
t
emp= b[j
]-f
[i
];
i
f(temp>=0)

4
5
{
f
f[
i
]=j
;br
eak
;
}
}
}
f
rag[
i]
=t
emp; bf
[f
f[
i
]]
=1;
}
pri
nt
f(
"\n
F i
l
e_no:
\tF
il
e_s
ize:
\t
Blo
ck_no
:\t
Blo
ck_si
ze:
\t
Frag
eme n
t")
;
fo
r(i
=1;
i
<=nf;
i
++)
pri
nt
f(
"\n%d\t\
t%d\t
\t
%d \
t\t
%d\t
\t
%d",
i
,f
[i
],
f
f[
i]
,
b[f
f[
i]
],
f
rag[
i]
);
getc
h();
}

I
NPUT
Ent
ert
hen
umbe
rofbl
ocks:
3
Ent
ert
hen
umbe
roff
i
les:
2

En
tert
hesi
zeoft
hebl
ock
s:-
Bl
ock1:
5
Bl
ock2:
2
Bl
ock3:
7

Ent
erthes
izeoft
hef
i
les
:-
Fi
l
e1 :
1
Fi
l
e2 :
4

OUTPUT
Fil
eNo Fi
l
eSi
ze Bl
ockNo Bl
ockSi
ze Fr
agme
nt
1 1 1 5 4
2 4 3 7 3

4
6
BEST- FI
T
#incl
ude<stdio.
h>
#i
nclude<c
o ni
o .
h>
#defi
nema x2 5
voi
dma in(
)
{
i
ntfra
g[max ]
,b[max],
f
[ma x],
i
,
j,
nb,nf
,
temp,l
owes
t=1
000
0;s
tat
i
cin
tbf
[ma
x],
f
f[
max
];
cl
rscr
();
pri
ntf
("
\nEnterthen u
mb erofbl
ocks:
")
;
scanf
("
%d "
,&n b);
pri
ntf
("
Enterth enumbe roffi
le
s :
"
);
scanf
("
%d "
,&n f)
;
pri
ntf
("
\nEntert h
es i
zeo ftheblock
s:-
\n"
);
for
(i
=1;
i<=n
b ;
i++)
pri
ntf
("
Block%d :
",
i
);
scanf
("
%d "
,&b[ i
])
;
pri
ntf
("
Enterth esi
zeo fthefi
les:
-\n"
);
for
(i
=1;
i<=n
f;i
++)
{
pri
ntf
("
Fi
le%d: ",
i
);
scanf
("
%d "
,&f[i]
);
}
for
(i
=1;
i<=n
f;i
++)
{
for
(j
=1;
j<=nb;j
++)
{
i
f(
bf[j
]!
=1)
{
te
mp= b[j
]-
f[i
];
i
f(
temp> =0
)
i
f(
lowest
>temp)
{
ff
[i
]
=j;
l
owe s
t=temp ;
}
}
}
f
rag[
i]
=l
o west;
bf[
ff
[i
]
]=1;
l
owest=10000;
}
pri
nt
f(
"\nFil
eNo \
tFi
l
eSize\t
Blo
ckNo\tBl
ockSiz
e\tFr
agment
")
;
for
(i
=1;
i
< =nf&&ff
[i
]!
=0;
i
++)
pri
nt
f(
"\n%d \t
\t
%d\t
\t%d\t
\t
%d\t\
t%d
",
i,
f[
i
],
ff
[i
]
,b[
ff
[i
]
],
fr
ag[
i]
);
get
ch(
);
}

4
7
I
NPUT
Ent
ert
henumbero
fbl
ock
s:3En
tert
he
numbe
roffi
l
es:
2

En
tert
hesi
zeoft
hebl
ock
s:-
Bl
ock1:
5
Bl
ock2:
2
Bl
ock3:
7

Ent
erthes
izeoft
hef
i
les
:-
Fi
l
e1 :
1
Fi
l
e2 :
4

OUTPUT
Fi
l
eNo F
il
eSiz
e Bl
ockNo Bl
ockSi
ze F
rag
men
t
1 1 2 2 1
2 4 1 5 2

4
8
FI
RST–F I
T
#i
nclude<stdi
o.h>
#i
nclude<coni
o .
h>
#defi
nema x2 5
voi
dma i
n(
)
{
i
ntfr
a g[
ma x]
,b[max],
f
[ma x]
,i
,
j,
nb,
nf
,t
emp,h
igh
est
=0;
sta
ti
cintbf[ma x]
,f
f[
max ];
cl
rscr(
);
pri
nt
f("
\n\tMe mo r
yMa nagementScheme-WorstFi
t
")
;pr
i
ntf
("
\nEn
tert
he
numb erofblocks:
")
;
scanf(
"%d",
&n b);
pri
nt
f("
Enterthen umbe roff
il
es:
")
;
scanf(
"%d",
&n f
);
pri
nt
f("
\nEnterthes i
zeo ft
heb l
ocks
:-
\n"
);
for
(i
=1;i
<=nb;
i++)
{
pri
nt
f("
Block%d :
"
,i
);
scanf(
"%d",
&b[i])
;
}
pri
nt
f("
Enterthes i
zeo fthefi
l
es:-
\n"
);
for
(i
=1;i
<=nf
;i
++)
{
pri
nt
f("
Fil
e%d: "
,i
);
scanf(
"%d",
&f[i
]);
}
for
(i
=1;i
<=nf
;i
++)
{
for(j
=1;j
<=nb;
j++)
{
i
f(bf[j
]!
=1)
{
temp= b[
j]
-f
[i
];i
f(
temp>=0)
i
f(highest
<temp)
{
ff
[i
]=j
;
highest=
temp;
}
}
}
frag[i
]=hi
ghest;
b f
[f
f[
i
]]
= 1
;highest
=0;
}
printf
("
\nFi
le
_ no:
\t
Fi
le_si
ze:\t
Blo
ck_no
:\t
Blo
ck_si
ze:
\t
Frag
eme n
t")
;
for(i
=1;i
<=n
f;
i++)
printf
("
\n%d\t\t
%d \
t\t
%d \t
\t%d\t
\t
%d",
i
,f
[i
],
f
f[
i]
,
b[f
f[
i]
],
f
rag[
i]
);
getc
h();
}

4
9
I
NPUT
Ent
ert
hen
umbe
rofbl
ocks:
3
Ent
ert
hen
umbe
roff
i
les:
2

En
tert
hesi
zeoft
hebl
ock
s:-
Bl
ock1:
5
Bl
ock2:
2
Bl
ock3:
7

Ent
erthes
izeoft
hef
i
les
:-
Fi
l
e1 :
1
Fi
l
e2 :
4

OUTPUT
Fil
eNo Fi
l
eSi
ze Bl
ockNo Bl
ockSi
ze Fr
agme
nt
1 1 3 7 6
2 4 1 5 1

RESULT:
Thust
hepr
ogr
amh
asb
eeni
mpl
eme
nte
dan
dex
ecut
eds
ucc
ess
ful
l
y.

5
0
EX.
NO:
12 SI
MULATEPAGI
NGTECHNI
QUEOFMEMORYMANAGEMENTDATE:

AI
M:
Towr
i
teapr
ogr
amt
osi
mul
at
ePa
gin
gte
chn
iqu
eofme
mor
yma
nag
eme
nt.

AL
GORITHM:
STEP1:St
artt
heprogra
m
STEP2:Ent
ert
h enumberofpage
sinthememor
y
STEP3:Ent
ert
h epagesi
ze
STEP4:Tocal
cula
teproce
ssaddres
sinth
epagi
ngt
echn
iqu
es
STEP5:St
optheprogra
m

PROGRAM:
#in c
lude<stdio.
h>
#in c
lude<con i
o.h>
ma i
n()
{
i
n tnp,
ps ,
i
;
i
n t*sa;
clrs
cr()
;
print
f(
"Enterhowma n
ypa g
es\n"
);
sc a
nf("
%d" ,
&n p);
print
f(
"Enterth epa gesiz
e\ n"
);
sc a
nf("
%d" ,
&ps );
sa =
(i
nt*)mall
oc (2* n
p);
for(
i=0;
i<np;
i++)
{
sa[i
]=
(i
n t
)ma ll
oc (ps)
;
pri
ntf
("page%d\ taddres
s%u \n"
,
i+1
,sa
[i
])
;
}
ge tch(
);
}

I
NPUT:
Ent
erh
owma n
ypa g
es:
5
Ent
ert
hepa
ges i
ze:
4

OUTPUT:
page1addr
ess
:1894
page2addr
ess
:1902
page3addr
ess
:1910
page4addr
ess
:1918
page5addr
ess
:1926

RESULT:
Thust
hepr
ogr
amf
orpa
gin
gte
chn
iqueo
fme
mor
yma
nag
eme
ntha
sbe
eni
mpl
eme
nte
dan
dex
ecu
teds
ucc
ess
ful
l
y.
50
EX.
NO:13 SI
MULATEAL
LPAGEREPLACEMENTALGORI
THMS
A) FI
FO B)
LRU C)LF
U
a)F
IFO:

AI
M:
Apr
ogr
amt
osi
mul
at
eFI
FOPa
geRe
pla
ceme
ntAl
gor
i
thm

AL
GORI
THM:
STEP1 :Sta
rtth epr o
cess
STEP2 :Decl
a reth esi
zewithrespectt
opa g
el engt
h
STEP3 :Chec kth eneedofreplace
me ntf
romt hepaget
omemor
y
STEP4 :Chec kth eneedofreplace
me ntf
romo ldpaget
one
wpagei
nme
mor
y
STEP5 :For
maq ueuetoholda l
lpages
STEP6 :I
nsertthepa gerequir
eme mo ryi
nt
ot hequeue
STEP7 :Chec kfo rbadre
placeme ntan
dpa gefaul
tSTEP
8:Gett
h enumbe rofproces
s estob ei
nse
rte
dSTEP9:
Di
s pl
aythevalue s
STEP1 0:St
opt h eprocess

PROGRAM:
#i
nclude<stdi
o.h>
#i
nclu
de <
c oni
o .
h>
main(
)
{
i
nti,
j,k,f
,pf=0,count=0,
rs[
25],
m[10],
n;
c
lr
scr(
);
pri
nt
f(
"\nEn terthel
e n
gthofref
ere
nces t
ri
ng--")
;sc
a n
f("
%d",
&n)
;
pri
nt
f(
"\nEn tertheref
erenc
es t
ri
ng--"
);
for
(i
=0;
i<n;
i++)
scanf
("
%d ",
&rs[i
]
);
pri
nt
f(
"\nEn terno.off
rames--")
;
scanf
("
%d ",
&f);
fo
r(i
=0;
i
< f
;
i++)
m[i
]=-
1;
pr
intf(
"\
nTh ePa g
eRe pl
acementProc
e s
sis--\n"
);
for
(i=0;
i<n;
i
++)
{
f
or(
k =0;
k<f;
k++)
{
i
f(
m[k]==r
s [i
])

br
ea k;
}
i
f(
k==f
)
{
m[count
++]=rs
[i
];pf
++;
}f
or(
j=0;
j<f
;
j++)
pr
intf
("
\t%d"
,m[j]
);
i
f(
k==f)
pr
intf
("
\tPF No .%d" ,
pf)
;
pr
intf
("
\n")
; i f(
c o
unt==f
)
count=
0;
}
pr
intf
("
\nTh enumbe rofPag
eFa
ult
sus
ingF
IFOa
re%d"
,
pf)
;ge
tch(
);
}

5
1
I
NPUT
Ent
erthele
ngthofr
efe
ren
ces
tri
ng–2
0
Ent
ertheref
ere
ncest
ri
ng-- 7012030423032120170
1Ente
rn o.
offr
ames-- 3

OUTPUT
ThePa
geRe
pla
cemen
tPr
oce
ssi
s–
7 -1 - 1 PFNo.
1
7 0 - 1 PFNo.
2
7 0 1 PFNo.
3
2 0 1 PFNo.
4
2 0 1
2 3 1 PFNo.
5
2 3 0 PFNo.
6
4 3 0 PFNo.
7
4 2 0 PFNo.
8
4 2 3 PFNo.
9
0 2 3 PFNo.
10
0 2 3
0 2 3
0 1 3 PFNo.
11
0 1 2 PFNo.
12
0 1 2
0 1 2
7 1 2 PFNo.
13
7 0 2 PFNo.
14
7 0 1 PFNo.
15

Then
umbe
rofPa
geF
aul
t
sus
ingF
IFOa
re1
5

RESULT:
Thu
sthepr
ogr
amf
orF
IFOPa
geRe
pla
ceme
ntAl
gor
i
thmha
sbe
ens
imu
lat
eda
nde
xec
ute
dsuc
ces
sful
l
y.

52
b)LRU:
AIM:
Aprogramt os imul at
eL RUPa geRe place
me ntAlgori
thm
ALGORI THM:
STEP1 :
Startt hepr oces s
STEP2 :
De claret hes i
ze
STEP3 :
Ge tthen umb erofpa gestobei nser
te d
STEP4 :
Ge tthev al
ue
STEP5 :
De clarec ou nt
e rands t
ack
STEP6 :
Se l
ec tthel eastrecentl
yuse dpag ebyc ount
e rv
alue
STEP7 :
Stac kt hema ccordi
ngthes e l
ect
ion.
STEP8 :
Displa yth evalue s
STEP9 :
Sto pt hepr oces s
PROGRAM:
#incl
ud e<stdio.
h >
#inc
lude<co nio.
h >
ma i
n()
{
i
n ti
,j,k,min ,rs[25],
m[ 10],coun
t[10],f
l
a g[
25 ]
,n,f
,pf=0,
n e
xt=
1;c
lr
scr
()
;
print
f(
"Entert helengthofr efe
rences tr
ing--");
sc a
nf("
%d ",
&n );
pr i
ntf
("
En t
e rt h
er eferences t
ri
ng- -")
;
for(i
=0;i
<n;i
++)
{
scanf(
"%d",
&rs [i
])
;
fl
ag[i
]=0;
}
print
f(
"Enterth en umb e roffr
ame s--");
sca nf
("
%d ",
&f);
for(i
=0;i
<f;
i
++)
{
count[
i]
=0;
m[ i
]=-
1;
}
print
f(
"\nThePa g eRe placementpro ces
sis- -\n"
);
for(i
=0;
i<n;
i
++)
{
for(j
=0;
j<f
;j
++)
{
i
f(
m[ j]==rs[i
]
)
{
fl
ag [i
]=1;coun t[
j]
=nex
t;
nex t++;
}
if
(f
lag [i
]
= =0)
{
i
f(i
<f)
{
m[i]=rs[
i
];
coun t
[i
]=
next
;
next++;
}
e l
se
{

5
3
m[ min]=
rs[i]
;
count[mi
n]= n
ext
;
next++;
}
pf++;
}
for(
j=0;j
<f
;j++)
pri
ntf(
"%d\ t"
,m[j
])
;
i
f(f
lag[i
]==0)
pri
n t
f(
"PFNo .-
-%d",pf
);
pri
n t
f(
"\n");
}
pri
n t
f(
"\nThen umberofpag
efa
ult
sus
ingL
RUa
re%d"
,
pf)
;
getch();
}

I
NPUT
En
tert
hel
engt
ho fr
efe
ren
cestr
i
ng-
-20
En
tert
her
efe
rencestr
i
ng--70120304230321201701
En
tert
hen
umb eroff
rames-
-3

OUTPUT
ThePageRe
pla
ceme
ntpr
oce
ssi
s--
7 -1 -1 PFNo.–1
7 0 - 1 PFNo.–2
7 0 1 PFNo .–3
2 0 1 PFNo .–4
2 0 1
2 0 3 PFNo .–5
2 0 3
4 0 3 PFNo .–6
4 0 2 PFNo .–7
4 3 2 PFNo .–8
0 3 2 PFNo .–9
0 3 2
0 3 2
1 3 2 PFNo .–10
1 3 2
1 0 2 PFNo .–11
1 0 2
1 0 7 PFNo .–12
1 0 7
1 0 7
Then
umbe
rofpa
gef
aul
t
sus
ingL
RUa
re12

RESULT:
Thust
hepr
ogr
amf
orL
RUPa
geRe
pla
cementAl
gor
i
thmha
sbe
ens
imu
lat
eda
nde
xec
ute
d
su
ccessf
ul
ly
.
54
C)LF
U:

AI
M

Towr
i
teaCpr
ogr
amt
opa
ger
epl
ace
men
tLF
U(L
eas
tFr
eque
ntl
yUs
ed)a
lgo
ri
thm.

ALGORITHM:
St
ep1:Star
tth eProgr
a m
St
ep2:Declarethesiz
e .
St
ep3:Getthen umbero fpagest
obeissued.
St
ep4:Declarecounterands t
ack
St
ep5:Sele
c ttheLRUpa gebycoun
terval
ue
St
ep6:Stackthema ccordi
n gt
hesel
ecti
on
St
ep7:Stopthee xecuti
on

PROGRAM
#i
nclude<st
dio.h>
#i
nclude<conio.
h>voidma i
n(
)
{
i
ntg=0,a[
5],
b[20 ]
,p=
0,q=0,
m=0,
h,
k,
i
,q1=1,
j,
u,
n;charf=
'F'
;
cl
rscr
()
;
pri
ntf
("
Entert hen umbe ro fpa
ge s:
"
);sc a
nf(
"%d",
&n);
pri
ntf
("
Enter %d Pa g
e Nu mber
s :
"
,n)
;f or(
i
=0;i
<n;
i
++)
scanf
("
%d",&b[ i
]
);
for
(i
=0;
i<
n ;
i
++)
{i
f
(p==0)
{
i
f(
q>=3)
q=0;
a[
q ]
=b[
i]
;
q++;
i
f(
q 1<
3)
{
q1=q;
//g=1;
}
}
pri
nt
f("
\n%d",
b [i
]
);
pri
ntf
("
\t
");
for
(h=0;
h<q1;h++)
pri
ntf
("
%d",
a [
h] )
;
i
f(
(p==0)
&&( q<=3))
{
pri
ntf
("
--
>%c "
,f);
m++;
}
p=0;
g=0;
i
f(
q 1=
=3)
{
for
(k=0;
k<q1;
k ++)
{
i
f(
b [
i
+1]==a[k
])

5
5
p=1;
}
for
(j
=0;
j<q1;
j++)
{u=
0;
k=i
;
wh i
l
e(k>=(i
-1)
&&(k>
=0)
)
{
i
f(
b[k]
==a[j
])
u++;
k--;
}
i
f(
u==0)
q=j
;
}
}
el
se
{
for
(k=
0;k<q;
k++)
{
i
f(
b[i
+1]==a[
k])
p=1;
}
}
}
pri
nt
f(
"\nNoo ffa
ult
s:
%d",
m);
get
ch(
);
}

I
nput
:
Ent
ert
heNumbe
rofPage
s:1
2
Ent
er12Pa
geNumber
s:
232152453252

Output:
22-
>F
323->F
223
1231->F
5251->F
2251
4254->F
5254
3354->F
2352->F
5352
2352
Noo ff
aul
ts
:7

RESULT:
Thu
sthepr
ogr
amwa
sev
alua
teda
nde
xec
ute
dsuc
ces
sful
l
y.

56
EX.
NO:
14 I
MPLEMENTALLFI
LEORGANI
ZATI
ONTECHNIQUESDATE:
A)SI
NGLEL
EVELDIRECTORYB)TWOLEVELC)HI
ERARCHI
CAL
AIM:
Writ
eaCprogr
amtos i
mula
tet
hef
oll
owi
ngfi
l
eorgani
zat
i
onte
chn
ique
s
a)Si
ngl
ele
vel
dir
ect
oryb)Twol
eve
ldi
rec
tor
yc)Hie
rar
chic
al

DESCRI PTION:
Thed i
rect
orystructurei
stheor gani
za t
ionoffil
esint
oah i
erarch yo ffol
der
s.Inas i
ngle-l
e vel
dir
ectory
syst
em,a l
lthef i
l
esa replacedino nedirectory.Thereisar ootdirectorywhi chh asallf
il
es.Itha sas i
mple
ar
ch i
t
ectureandtherea renos ubdir
ectori
es.Ad vanta
geofs i
ngleleveld i
rectorysyst
emi sthatitiseasytofin
d
afi
lei
nt hedire
ctor
y.I
nt hetwo -l
evel
direct
orys yste
m, eachuserhasownus erfi
l
edir
e ct
ory(UF D).Thesyst
e m
maint
ainsama st
erblockt hathasonee n t
ryfore achuse r
.Thisma s
te rblockc ont
ai
nst hea ddressesofthe
di
rect
oryoft heu se
rs.Wh enaus erjobs t
artsoraus erlogsin,thes y st
e m'sma st
erfil
ed i
re c
tory(MFD)i s
searc
hed .
Wh e
naus err ef
erstoapa r
ti
cularfi
l
e ,onl
yhisownUF Diss earche d.Thi
seffec
tiv
elys ol
vesthen a
me
col
li
si
onpr obl
ema ndi sol
atesu ser
sfromo nea nother
.Hiera
rchi
cal di
rec t
o r
ys tr
uctur
ea ll
owsu serstocreat
e
the
irowns u bd
ir
ector
iesa ndtoo r
gani
z ethei
rf i
l
e saccor
dingl
y.At r
eei sth emos tcommond ir
e ctor
ys t
ruct
ure.
Thetreeh asarootdi
rec t
ory,andeveryfi
lei
nt hes yst
emh asaun iquepa t
hn ame .Adir
ec t
ory(ors ubdi
rec
tory)
conta
insas etoff
il
esors ubdirec
tor
ies.

PROGRAM: (SI
NGL ELEVELDI RECTORYORGANI ZATI
ON)
#incl
ud e
< s
tdio.
h >
St r
uct
{
ch ardname [10],
fname[10][
10];
i
n tfc
n t
;
}dir
;
vo i
dma i
n()
{
i
n ti
,ch;
ch arf[
30];
clrscr
();
dir.
fcnt=0;
print
f(
"\nEntern ameo fdi
rect
o r
y--");
sc anf
("%s",di
r.dname);
wh i
l
e(1)
{
printf
("
\n\n1.Cr eat
eF i
l
e \
t2.Dele
teFil
e\t3.
Sea
rchF
il
e\n4.Di
spl
ayF
il
es\
t5.
Exi
t
\nEn
tery
ourc
hoi
ce"
);
sca
nf(
"%d"
,
&ch)
;
switch(ch)
{
ca se1 :
printf
("\
nEn t
erth enameo fthefil
e--");
sc anf
("%s",
d i
r
.fn
a me[di
r.
fcnt
]);
dir
.f
cnt++;
break;
ca s
e2 :
print
f(
"\nEnterthen ameoft hefi
l
e--");
sc anf
("%s",
f);
for(i
=0;i
<dir
.
fcnt;
i++)
{
i
f(str
cmp( f
,dir.
f
n ame[i
])=
=0)
5
7
{
pr
intf(
"Fi
l
e%si sd el
eted",
f)
;
str
cpy (
dir
.f
name [
i],
di
r.
fname[di
r
.f
cnt
-1])
;
break;
}}
i
f(
i
== di
r.
fcnt
)
pr
int
f("F
il
e%sn o tf
ou nd"
,f
);
els
e
di
r.
f
c nt-
-;
break;
case3:
pr
intf(
"\
nEnterthen ameo ft
hefi
le--")
;
scanf("
%s "
,f
);
for
(i
= 0;
i<
dir.
f
cnt;
i
++)
{
i
f(
strcmp(f,di
r
.f
n ame[i
])==
0)
{
pr
int
f("F
il
e%si sfound" ,
f)
;
break;
}}
i
f(
i
== di
r.
fcnt
)
pr
int
f("F
il
e%sn o tf
ou nd"
,f
);
break;
case4:
i
f(di
r.
fcnt==
0)
pri
ntf
("\nDi
rect
o r
yEmpt y
");
els
e
{
pri
ntf("
\nTheFil
esa re--")
;
for
(i
= 0;
i<
dir.
f
cnt;
i
++)
pri
ntf("
\t
%s "
,di
r.
f
n ame [
i
]);
}brea k;
default
:
exi
t(
0) ;
}}
get
c h()
;
}

OUTPUT:
Ent
ernameofdi
rect
ory--CSE
1. Creat
eFi
le 2.Del
et
eFil
e 3 .Sear
chFil
e
4.Di
spl
ayFi
les5.
Exit Ent
ery
ourchoi
ce–1
Ente
rthenameofthefi
le--A
1.Crea
teFi
l
e 2 .Del
eteF i
l
e 3 .
Sear
chFil
e
4.Di
spl
ayFi
les5.
Exit Ent
ery
ourchoi
ce–1
Ente
rthenameofthefi
le--B
1.Crea
teFi
l
e 2.Del
eteFi
l
e3.Sear
chFil
e
4.Di
spl
ayFi
les5.
Exit Ent
ery
ourchoi
ce–1
Ente
rthenameofthefi
le--C
1.Crea
teFi
l
e 2 .Del
eteF i
l
e 3 .
Sear
chFil
e
4.Di
spl
ayFi
les5.
Exit Ent
ery
ourchoi
ce–4
TheFil
esar
e--ABC
58
1.CreateFil
e 2 .Dele
teF i
le 3. Sear
chFi
l
e
4.Displ
ayF i
l
es 5.Exi
t En
tery
ourc
hoi
ce–3
Ente
rthen ameo fthefi
l
e–ABC
Fil
eABCn otfoun
d
1.CreateFil
e 2 .Dele
teF i
le 3. Sear
chFi
l
e
4.Displ
ayF i
l
es5.Ex i
tEnteryourc
hoic
e–2
Enterthenameoft hefi
le–B
Fi
l
eBi sde l
et
ed
1.Creat
eF i
l
e2 .Delet
eF i
le 3.Sear
chFi
l
e
4.Displ
ayF i
l
es 5.Exi
t En
tery
ourc
hoi
ce–5

PROGRAM: (TWOL EVELDI RECTORYORGANI ZATION)


#in c
lude<std i
o.h>
Struct
{
ch ardname [10 ]
,
fname[10
][10];
i
n tfcnt;
}dir
[10];voi
d
ma i
n(
)
{
i
n ti
,ch,
dc nt,
k;
ch arf[
30] ,
d [30];
clrscr
();
dc nt
=0;
wh i
l
e(1)
{
printf
("
\ n
\ n1.Cr eat
eDirectory\t
2.CreateFil
e\t
3.Del
eteFi
le
");
pri
nt
f(
"\
n4.
Se archF i
le\t\t5.Di
spla
y\t6.Exit
\tEnt
e ryourchoi
ce--")
;
sc anf
("%d",&c h);
swi t
ch(ch )
{
ca se1 :
printf
("
\ n
En tern ameofdirectory--")
;
sc anf
("%s "
,dir[dcnt]
.
dname )
;
dir[dcnt]
.
fcnt= 0;
dc nt
++;
printf
("
Directo rycreat
ed")
;
bre ak;
ca se2 :
printf
("
\ n
En tern ameofthedi rect
ory--");
sc anf
("%s "
,
d );
for(
i=0;
i<dcn t;
i
++)
i
f(st
rcmp( d,dir
[i]
.
dname)==0)
{
print
f(
"En t
e rn ameofthef i
l
e- -")
;
sc anf
("%s",
d i
r[i
].
fname[di
r
[i
].
fcnt]
);
dir[i
]
.f
cn t
++;
printf
("
F i
l
ec re ated"
);
break;
}
i
f(i
==dc nt)
print
f(
"Directo r
y%sn otfound "
,d)
;
5
9
break;
case3 :
pri
nt
f("
\nEnternameo fthed i
r
e c
tory--"
);
scanf(
"%s",
d);
for(
i
=0 ;
i
<dcnt;
i
++)
{
i
f(
str
c mp(d,
dir
[i
].
dname )
= =
0)
{
pri
nt
f("
Enternameo fthefil
e--")
;
scanf(
"%s",
f);
for(
k=0;
k<dir[
i
].
fcnt
;k
++)
{
i
f(
str
c mp(f,
dir
[i
].
fn
ame [k])
==0)
{
pri
nt
f("
Fil
e%si sdel
eted",f
);
di
r[
i]
.f
cnt--
;
str
cpy(dir
[i
]
.f
name [
k]
,di
r[i
]
.f
name [
dir
[i
]
.f
cnt]
);
got
o
j
mp;
}}
pri
nt
f("
Fil
e%sn otfound",
f)
;
gotojmp;
}}
pri
nt
f("
Direct
ory%sn otfound"
,d)
;
j
mp: break;
case4 :
pri
nt
f("
\nEnternameoft hed i
r
e c
tory--"
);
scanf
("%s",
d);
for
(i
=0;i
<dcnt
;i
++)
{
i
f(
str
c mp(d,
dir
[i
].
dname )
= =
0)
{
pri
nt
f("
En t
erthenameoft hefil
e--");
scanf(
"%s",
f);
for(
k=0;
k<dir[
i
].
fcnt
;k
++)
{
i
f(
str
c mp(f,
dir
[i
].
fn
ame [k])
==0)
{
pri
nt
f("
Fil
e%si sfoun
d" ,
f);
gotojmp1 ;
}}
pri
nt
f("
Fil
e%sn otfound",
f)
;
gotojmp1;
}}
pri
nt
f("
Direct
ory%sn otfound"
,d)
;
j
mp1 :break;
case5:
i
f(
dcnt==0)
pri
nt
f("
\nNoDi r
ector
y's");
else
{
pri
nt
f("
\nDir
ector
y\t
Fil
es");
for(
i
=0 ;
i
<dcnt;
i
++)
60
{
pr
i
ntf
("
\n%s
\ t
\t
",
di
r[
i]
.
dname);
for
(k=
0;k
<di
r[i
]
.f
cnt
;k
++)
pri
nt
f(
"\t
%s"
,di
r[
i]
.
fname[
k])
;
}}
br
eak;
de
faul
t:
exi
t(
0);
}}
ge
tch(
);
}

OUTPUT:
1.
Cre at
eDir
ector
y 2.Creat
eF i
l
e 3.
Del
eteFi
l
e
4.SearchFi
l
e 5.Dis
play 6.
Exi
tEnt
eryou
rchoi
ce-
-1
Ente
rn ameofdir
ector
y--DIR1
Dir
ectorycr
eat
ed
1.CreateDi
rect
ory 2.Creat
eFil
e 3.Del
et
eFil
e
4.Sea r
chFil
e 5
.Displ
ay 6.
Exi
tEnt
eryourc
hoi
ce-
-1
Ente
rn ameofdir
ector
y--DIR2
Director
ycrea
ted
1.CreateDi
rect
ory 2.Creat
eFil
e 3.
Del
et
eFi
l
e

4 .
Sea r
chF i
l
e 5.Dis
pl ay 6.
Exi
tEn
tery
ourc
hoi
ce-
-2
Enternameo fthedire
ctory–DI R1
Enternameo fthefi
le--A1
Fi
lecreated
1 .
Cre a
teDirec t
ory 2.Crea teFi
le 3.
Del
eteFi
l
e
4.SearchFil
e 5.Dis
pl ay 6.
Exi
tEnt
eryo
urc
hoi
ce-
-2
Enternameo fthedire
ctory–DI R1
Enternameo fthefi
le--A2
Fil
ecreated
1.Cre a
teDirec t
ory 2.Crea teFi
le 3
.Del
et
eFi
l
e
4.Sea r
chF i
l
e 5.Dis
pl ay 6
.Ex
it
Enteryou rchoice–2
Ente
rn ameo ft
h edi
rector
y–DI R2
Enternameo fthefi
le--B1
Fil
ecreated
1 .
Cre at
eDirec t
ory 2.Crea t
eF i
l
e 3.
Del
eteFi
l
e
4.SearchFil
e 5.Di
s play 6.
Exi
tEnt
eryourc
hoi
ce–5
Dir
ectoryFi
les
DIR1 A1 A2
DIR2 B1
1 .
Cre at
eDirec t
ory 2.Crea teFi
le 3.
Del
eteFi
l
e
4 .
Sea r
chF i
le 5.Display 6.
Exi
tEnt
eryou
rchoi
ce-
-4
En t
ernameo fthed i
rect
ory–DI R
Director
yn otfound
1 .
Cre at
eDirec t
ory 2.Crea teFi
le 3.
Del
eteFi
l
e
4 .
Sea r
chF i
le 5.Di
s play 6.
Exi
tEnt
eryourc
hoi
ce-
-3
En t
ernameo fthed i
rect
ory–DI R1
Enternameo ft
h efi
l
e- -A2
Fi
leA2isd eleted
6
1
1.Cr
eat
eDi
r
ect
ory 2.Cr
eateF
il
e3.
Del
eteFi
l
e
4.Se
arc
hFi
l
e 5
.Dis
pla
y 6.
Exi
tEnt
ery
ourc
hoi
ce-
-6

PROGRAM: (
HI ERARCHI CALDI RECTORYORGANI ZATI
ON)
#in cl
u de <std i
o.h>
#inclu de< graph ics.h
>
struc ttree _eleme nt
{
ch arn a me [20 ]
;
i
n tx, y,ftype ,l
x ,rx,nc,l
evel;
stru cttree _e l
eme nt* l
i
nk[
5 ]
;
};
typed e fs t
ru cttree _
e l
eme ntnode;
vo i
dma i
n ()
{
i
n tg d= DETECT, g m;
no de* root;
root =NUL L ;cl
rs cr()
;
cre ate(&r oo t,
0,"
r oot"
,0,
639 ,
320);
clrscr();
i
n i
tg r
a ph (&g d,
&g m,"c:
\tc\
BGI "
);
displa y(roo t);
ge tch();
close graph ()
;
}
cre ate(n ode* *r
o ot,i
ntle
v,char*dname,i
ntl
x,
intrx,
i
ntx
)
{
i
n ti,ga p;
i
f(*roo t==NUL L)
{
(*root)= (
n od e* )ma l
loc(
sizeof(
node))
;pri
nt
f(
"En t
er
na meofdi r/ f
i
le(u nder%s ):",
dname);f
fl
ush(
stdin)
;
ge ts((*root)- >
n ame )
;
printf("ente r1f o rDir/2forfi
le:
");
sc anf("%d ",&(*ro ot)
->ft
ype )
;(*r
oot)
->leve l
= l
e v;
(*root)->y =5 0+lev*50 ;
(*root)-> x=x ;
(*root)-> l
x =l
x ;
(*root)-> rx=rx;
for(i=
0 ;i
< 5;
i++)
(*root)->li
n k[i
]=NUL L;
i
f((*r
o o t)
-> f
type = =1)
{
print
f("Noofs ubd ir
e ct
ori
es/fi
l
es(f
or%s )
:"
,
(*r
o ot
)-
>na
me);
sc anf("%d ",&(*root)>nc);
i
f((*r
o o t
)->n c==0 )
ga p=rx -l
x;
else
ga p=(rx -l
x)/ (
*root )-
>n c;
62
for(i
=0 ;
i
<(*r
oot)-
>nc;
i++)cr
eate
(&((
*r
oot)
>l
in
k[i
])
,l
ev+1,
(*
root
)>
name
,l
x+g
ap*
i,
l
x+g
ap*
i+g
ap,
l
x +ga p*i
+gap/2);
}
else
(
* root)
->nc=0;
}}
display(
node* r
oo t
)
{
i
n ti
;
se tt
ex t
sty
le(
2,0,
4);
se tt
ex t
jus
ti
fy(
1 ,
1);
se tf
i
ll
s t
yl
e(1,
BLUE);
se tcolor
(14)
;
i
f(roo t!
=NUL L)
{
for(i
=0 ;
i
<root
->nc;i
++)
l
ine (
ro o
t->
x,r
oo t
->y
,r
oot-
>l
ink
[i
]-
>x,
root
->l
i
nk[
i
]->
y);i
f
(root
->ftype==1)
ba r
3 d(
root
->x-20,
root
->y
-10,
root
->x
+20,
root
>y+10,0
,0)
;el
se
f
il
lell
i
ps e(
root
->x,
root-
>y,
20,
20);o
uttextxy(
root
->x,r
oot-
>y,
root
->n
ame )
;
for(i
=0 ;
i
<root
->nc;i
++)
display(r
oot->
li
nk[i
])
;
}}

OUTPUT:
Ent
erNameo fdir
/f
il
e(underroot
):ROOT
Ent
er1forDir
/2forFil
e:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rROOT) :
2En t
er
Nameofd i
r
/fi
l
e(underROOT) :
USER1En ter1
f
orDir
/2forFi
le
:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rUSER1):1
Ent
erNameo fdi
r/f
il
e(underUSER1 )
:SUBDIR1En
ter1
f
orDir
/2forFi
le
:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rSUBDIR1):
2
Ent
erNameo fdir
/f
il
e(underUSER1):JAVA
Ent
er1forDir
/2forFil
e:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rJAVA):0Ente
r
Nameofd i
r
/fi
l
e(underSUBDI R1)
:VBEn t
er1
f
orDir
/2forFi
le
:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rVB):
0
Ent
erNameo fdir
/f
il
e(underROOT) :USER2
Ent
er1forDir
/2forFil
e:1
Noo fsubdi
rect
ori
es/fi
l
es(forUSER2 )
:2
Ent
erNa meofd i
r/
fil
e(un
d erROOT) :A
Ent
er1forDir
/2forFil
e:2
Ent
erNameo fdi
r/f
il
e(underUSER2 )
:SUBDIR2En
ter1
f
orDir
/2forFi
le
:1
Noofsubdi
rect
ori
es/fi
le
s(f
o rSUBDIR2):
2

En
terNa
meofdi
r
/fi
l
e(un
derSUBDI
R2)
:PPL
6
3
Ent
er1forDi
r/2forFi
le:1
Noo fs
ub di
r
e ct
ori
es/f
i
les(f
orPPL ):2
Ent
erNa meo fdir
/f
il
e(unde rPPL)
:B
Ent
er1forDi
r/2forFi
le:2
Ent
erNa meo fdi
r/f
il
e(
un derPPL )
:C
Ent
er1forDi
r/2forFi
le:2
En
terNameo fdi
r/f
i
le(
un d
erSUBDI R):
AI
Ent
er1forDi
r/2forFi
le:1
Noofsubdi
rect
ori
es/f
il
es(f
o rAI
):2
Ent
erNameo fdi
r/f
il
e(
un derAI)
:D

En
ter1f
orDi
r
/2f
orFil
e:2
En
terNa
meofdi
r
/fi
l
e(und
erAI
)
:E
En
ter1f
orDi
r
/2f
orFil
e:2

RESULT:
Thust
hepro
gra
mfo
rfi
l
eor
gan
iza
ti
ont
ech
niq
uesha
sbe
eni
mpl
eme
nte
dan
dex
ecut
eds
ucc
ess
ful
l
y.

64
EX.
NO:
15 I
MPL
EMENTATI
ONOFF
ILEALL
OCATI
ONSTRATEGI
ESDATE:

AIM:
Towr it
eaCpr ogramt os imul
atet hef ol
lowingfil
ea ll
oc a
ti
ons t
rate
gies.
a)Se q uenti
alb )Li
nke dc )Indexed
DESCRI PTION:
Af i
leisac o l
lec t
i
onofda t
a,us ua ll
ys t
ore do nd i
sk.Asal ogi
ca len t
it
y,af i
lee nab l
est od i
videdatainto
me ani
ngfulg r
oups.Asaphy si
c alen ti
ty,af i
l
es houldb econ si
deredint ermsofi t
so r
g ani
za t
ion.Thet er
m" fi
le
organi
zati
on"refer
st ot hewa yi
nwh ichd atai
ss toredinaf i
l
ea nd,consequ entl
y,theme t
h od(s)bywh ic
hitcanbe
accessed.
SEQUENTI ALF I
LEAL LOCATI ON:I nt hisf i
l
eor ganiza
ti
on,there c
ordso fthef i
l
ea res t
ore do nea ft
eranother
bothph ysi
ca l
l
ya ndlo gi
c al
l
y.Thati s,rec ordwiths equencen umber16i slo cat
edj u s
ta ft
e rthe1 5thr e
co r
d.A
re
c ordofas equenti
al f
il
ec anonlybea cc essedb yr eadi
ngallt
h eprevi
ousr ec or
ds.
LI
NKEDF ILEAL LOCATI ON:Wi t
hl i
n keda l
l
ocati
o n,eachfil
eisalinkedli
s tofdiskbl ocks;thedi skblocksma ybe
scatt
ereda nywhereo nt hedisk.Thed ir
e ctor
yc on t
ai
n sapo i
ntertothefirsta ndla
s tblocksoft h efi
le.Eachblock
contai
nsapo i
nt
ertot hen extbl
oc k.
I
NDEXEDF ILEAL LOCATI ON: I
n dexe dfileal
loca t
ions t
rat
egyb ri
ngsallt
hepoi nt
erst ogetherin t
oo nelocati
on:an
i
nde xbloc
k .Eachfi
leh asi t
sowni n
d exbl ock,whi chisa narr
ayofd i
sk-blocka dd
res ses.Th eit
he nt
ryintheindex
bl
oc kpoint
st otheit
hbl ockofthef i
le.Th edirecto r
yc ont
ain
st headdresso ftheinde xblock.Tof inda ndreadthe
i
thb l
ock,t
h epo i
nt
erint heithin
d ex-blocke nt
ryi
su sed.

PROGRAM: (SEQUENTI ALF I


LEALLOCATION)
#incl
u de<stdio.h>
#incl
u d
e< co n
io .
h>
str
uc tfi
l
eTa ble
{
charname [20];
i
ntsb ,n
o b;
}f
t[
30 ]
;
voi
dma i
n (
)
{
i
nti
, j
,n;
chars [
20 ];
clr
scr()
;
pri
ntf("
Ente rnooff i
le
s:"
);
scanf("
%d ",
&n );
for
(i
= 0;
i<
n ;
i++)
{
pri
ntf(
"\nEn te
rf i
lename%d:",
i
+1 )
;
scanf("
%s ",
ft[
i].
name )
;
pri
ntf(
"Enters tart
ingbl
ockoff
il
e%d:",
i
+1);
scanf(
"%d ",
&ft[i
].
sb);
pri
ntf(
"Entern oo fblo
cksinf
il
e%d:",
i
+1);
scanf("
%d ",
&ft[i]
.
n ob)
;
}
pr
intf
("\
n En t
e rthefi
l
enametob esear
ched-
-")
;
scanf("
%s ",
s )
;
for
(i
= 0;
i<
n ;
i++)
i
f(
strcmp( s,f
t[i]
.
n a
me )
==0)
br
ea k;
i
f(i
==n)
pr i
n t
f("\
n F
il
eNotFound"
);
6
5
els
e
{
pr
int
f(
"\nF
ILENAMESTARTBL OCKNOOFBL OCKSBL OCKSOCCUPI
ED\
n")
;
pri
ntf
("
\n%s\t
\t
%d\t\
t%d\
t"
,f
t[
i
].
name,
f
t[
i]
.
sb,
f
t[
i]
.
nob
);f
or(
j=
0;j
<f
t[
i
].
nob;
j
++)
pr
int
f(
"%d,"
,f
t[
i
].
sb+j
);
}
get
ch()
;
}

OUTPUT:
En t
ernooffil
es:3
En t
erfi
l
ename1: A
En t
ersta
rti
ngblockoffi
l
e1: 85
En t
ernoofb l
ocksinfi
l
e1: 6
En t
erfi
l
en ame2: B
Enterst
art
i
n gbl
ocko ff
il
e2:102
En t
ernoofb l
ocksinfi
l
e2:4Enter
fi
lename3: C
En t
erst
art
ingblo
c koffi
l
e3:60
En t
ernoofb l
ocksinfi
l
e3:4
Entert
hefi
lenamet obes e
arche
d--B
F I
LENAME STARTBL OCK NOOFBL
OCKS BLOCKSOCCUPIED
B 102 4 10
2 ,
103
,104,
105

PROGRAM: (L I
NKEDF I
LEALLOCATION)
#inc
lude<stdi
o.h>
#inc
lude<coni
o .
h>
str
uctfi
leTabl
e
{
charname [
2 0];
intnob;
str
uctblock*s b;
}ft
[30];
str
uctblock
{
i
ntbno;
str
uctblock*n ext
;
};
v oi
dma in(
)
{
i
nti,j
,n;
chars[20];
str
uctblock*temp;
cl
rscr
();
print
f(
"Enternoo ff
il
es:")
;
scanf
("%d",
&n);for(
i
=0 ;
i
<n;
i++)
{
print
f(
"\nEnterfi
l
en ame%d: "
,i
+1)
;
s ca
nf("
%s "
,f
t[
i].
name);
pri
nt
f("
En t
ern oofblocksinf
il
e%d:"
,
i+1
);
66
scanf(
"%d",
&f t
[i]
.
n ob);
ft
[i
]
.s
b=(str
u ctb l
o c
k*)ma l
l
oc(
si
zeo f
(s
tru
c tblock
));
temp=
ft
[i
]
.sb;
pri
ntf
("
En t
e rtheb l
ocksofthefi
l
e:")
;
scanf(
"%d",
&t emp- >bno )
;
temp->next=NUL L;
for(
j=
1;j
<ft
[i
].nob;j
++)
{
temp->next=( s
tructblock*
)mal
loc(s
izeof(
stru
ctblock
));
temp=t emp- > next;
scanf(
"%d",
&t emp- >bno )
;
}
te
mp- >next=NUL L;
}
pri
nt
f(
"\nEn t
e rthefil
en ametob esear
c hed--")
;
scanf(
"%s",
s )
;
for(
i
=0;i
<n;
i++)
i
f(
str
cmp( s,ft
[i]
.
n ame)==0)
break;
i
f(
i==
n)
pri
nt
f(
"\nFi
leNo tFound "
);
else
{
pri
nt
f(
"\nFILENAMENOOFBL OCKSBL OCKSOCCUPI ED"
);
pri
ntf
("
\n%s \t
\ t
%d \t
",
ft
[i]
.
name,f
t[
i]
.n
ob);
temp=ft[
i
].
s b;
for(
j=
0;j
<ft
[i].
nob;j++)
{
pri
nt
f(
"%d ",
temp -
>bno)
;
temp=t emp- > next;
}
}
get
ch();
}

OUTPUT:
Ent
ernooffi
le
s: 2
Ent
erfi
l
e1: A
Ent
ernoofblock
sinfi
le1:4
Ent
erthebl
ocksofthefi
l
e1:122394
Ent
erfi
l
e2: G
Ent
ernoofblock
sinfi
le2:5
Ent
erthebl
ocksofthefi
l
e2:8877665544
Ent
erthefi
l
etobes e
a r
ched:G
FI
LENAME NOOFBL OCKS BL OCKSOCCUPI
ED88
G 5 77 66 5 5 4 4

PROGRAM: (
I
NDEXEDF
ILEALL
OCATI
ON)
#in
clude<s
tdi
o.
h>
#i
ncl
u d
e<coni
o.
h>
st
ructfi
l
eTabl
e
{
6
7
c harn ame [
20 ];
i
n tnob ,bl
ocks [
30];
}ft[
30];
vo i
dma i
n()
{
i
n ti
,j,n;
cha rs[20];
clrscr
();
pr i
ntf
("Enternoo ffi
les:"
);
sc anf
("%d "
,
&n );
for(i
=0;i
<n;i
++)
{
print
f(
"\nEn t
erfil
en ame%d: "
,i
+1);
sc anf
("%s",
ft[
i].
name );
pr i
ntf
("
En t
ern oo fblocksi
nfi
le%d:",
i+1);
sc a
nf("%d",
&ft[i
].
nob);
print
f(
"Enterth eblocksofthefi
l
e:"
);
for(j
=0;j<f
t[
i]
.nob;j
++)
sc anf
("%d "
,
&ft[i]
.
b l
ocks[
j])
;
}
print
f(
"\nEn t
e rthefi
lenamet obese ar
ched--"
);
sc a
nf("%s",
s);
for(
i=0;i
<n;
i
++)i f(
strcmp(s,
ft[i
].
name )==0)break;
i
f(i
==n)
print
f(
"\nFi
leNotF ound")
;
else
{
print
f(
"\nFILENAMENOOFBL OCKSBL OCKSOCCUPI
ED"
);
print
f(
"\n%s \t\t%d\t"
,f
t[
i]
.
name ,
f
t[
i]
.
no b)
;
for(
j=0;j
<ft
[i
].
n ob;j
++)
print
f(
"%d ,",
f
t[i]
.
b l
ocks[
j])
;
}
ge t
ch();}

OUTPUT:
Ent
ernooffi
l
e s
:2
Ent
erfi
le1:
A
Ent
ernoofblocksi
nfi
le1:4
Ent
erthebl
ocksofthefi
l
e1 :1
22394
Ent
erfi
le2:
G
Ent
ernoofblocksi
nfi
le2:5
Ent
erthebl
ocksofthefi
l
e2 :8
877665544
Ent
erthef
il
etob esear
ched:G
FI
LENAME NOOFBL OCKS BLOCKSOCCUPI
ED
G 5 88,
77,
66,
55,
441

RESULT:
Thu
sthepr
ogr
amf
orf
i
lea
ll
oca
ti
ons
tra
teg
iesha
sbe
eni
mpl
eme
nte
dan
dex
ecu
teds
ucc
ess
ful
l
y.
68
ADVANCEDEXPERI
MENTS

EX.
NO:
16 SI
MULATI
ONOFMVTANDMF
TMEMORYMANAGEMENTTECHNI
QUESDATE:

AI
M
Wr
i
teaCpr
ogr
amt
osi
mul
at
eth
eMVTa
ndMF
Tme
mor
yma
nage
men
tte
chn
iqu
es

DESCRI PTION
MF T(Mul
tipr
o gr
ammingwi thaF i
xednumb erofTasks)i
so neoftheo l
dme moryma nagement
te
chniquesinwh i
c hth ememor yispa r
ti
ti
onedin
tof i
xedsizepar
ti
ti
onsa n
de achj obi
sa ss
ign
e dtoa
part
it
i
on .Theme mor yassi
gnedt oapa rt
it
i
ond oe
sn otc ha
nge.MVT( Mul
ti
progr
ammi ngwit
haVa r
ia
ble
numb ero fTask
s)i stheme mor yma nagementtec
h ni
queinwh i
che achjobgetsjusttheamou ntof
me moryitneeds.Thatis,
thepa rt
i
ti
onin
go fmemo r
yisdy n
amicandcha n
gesa sjobsent
erandleavethe
syst
em.MVT i samor e` è
f
f i
ci
ent
''userofr e
sources.MF Tsuff
erswi ththepr obl
em ofi n
tern
al
fr
agme ntat
ionan
dMVTs uf
fer
swi t
he xt
erna
lfr
agmentat
ion.

PROGRAM: MF T
#inc
lud e<st
d i
o.h>
#in
clude <coni
o .
h>
ma i
n()
{
i
ntms ,b s,nob,e f
,n,
mp[ 10],
tif
=0; i
nt
i
,
p=0 ;
cl
rscr(
);
pri
ntf(
"Enterthet otal
me mor ya vail
abl
e(i
nBy te
s)--"
);
scanf(
"%d ",
&ms )
;
pri
ntf(
"Entertheb locksi
z e(inBy tes)-
-");
scanf(
"%d ",&bs);
nob=ms /bs ;
ef=
ms-n o b*bs;
pri
ntf(
"\nEnterthen umbe rofpr oces s
es--")
;
scanf(
"%d ",
&n);
for
(i
=0;i
<n ;
i
++)
{
pri
ntf(
"Enterme moryrequ i
redf orprocess%d(inBytes)
--"
,
i+1)
;
scanf(
"%d" ,
&mp[ i]
);
}
pri
ntf(
"\nNo .ofBlocksav ai
lableinme mory--%d",
nob);
pri
ntf
("\n\nPROCESS\ t
MEMORYREQUI RED\tALLOCATED\ tI
NTERNALFRAGMENTATI
ON"
);
for
(i
=0;i
<n&&p< nob;i
++)
{
pri
ntf
("\n%d \t\t
%d ",
i
+1 ,
mp[ i
]);
i
f(
mp[ i
]>b s )
pri
nt
f("
\ t
\tNO\ t\t
---"
);
el
se
{
pri
nt
f("
\t\t
YES\ t%d",
bs-mp[i
]);t
if=
ti
f+b s-mp[ i
];
p++;
}
}
i
f(i
<n)
pri
ntf
("\nMe mo ryisFul
l,Re ma i
ningProcessescannotbeacco
mod a
ted"
);
pri
ntf(
"\n\nTotalInte
rnalFrag me nt
ati
onis%d "
,t
i
f)
;
pri
ntf
("\nTotalEx t
ernalFragme ntati
onis%d",
ef)
;
getch()
;}

6
9
I
NPUT
Ent
erthetot
alme moryavai
l
abl
e(i
nBytes
)-- 1000
Ent
erthebl
oc ksi
ze(i
nBy t
es) 300
Ent
erthenumb erofproc
esses–5
Enterme moryrequ
ir
edforpr
ocess1(
i
nBy
tes
)-- 27
5
Enterme moryrequ
ir
edforpr
ocess2(
i
nBy
tes
)-- 40
0
Enterme moryrequ
ir
edforpr
ocess3(
i
nBy
tes
)-- 29
0
Enterme moryrequ
ir
edforpr
ocess4(
i
nBy
tes
)-- 29
3
Enterme moryrequ
ir
edforpr
ocess5(
i
nBy
tes
)-- 10
0
No.ofBl
ocksa v
ail
abl
einme mor
y-- 3

OUTPUT MEMORY I
NTERNAL
PROCESS REQUI
RED AL
L OCATED F
RAGMENTATI
ON
1 275 YES 25
2 400 NO --
--
-
3 290 YES 10
4 293 YES 7

Memo r
yisFul
l,Re
ma i
ni
ngPr o
cesse
sc annotbe
ac
commo datedTota
lIn
tern
alFra
gmen t
ati
onis 42
Tot
alExt
ern
a l
Fragmentat
i
onis 100

MVT
#incl
ude <s
tdio.h>
#incl
u de<c
o ni
o .
h>
ma i
n( )
{
intms ,mp[10],i
,temp,n=0;
cha rch=' y'
;
clrs
c r(
);
printf(
"\
nEn t
ert hetotal
me mor yavai
la
ble(i
nBytes
)--"
);
sc a
n f(
"%d",
&ms );
temp= ms ;
for(i
=0;ch==
'y'
;
i
++, n++)
{
printf(
"\
nEn t
erme moryr equir
e dforproce
ss%d( i
nBytes
)--"
,
i+1)
;
sc a
n f(
"%d",
&mp[ i
])
;
if
(mp[ i
]<=t
emp)
{
printf(
"\
nMe mor yisall
oc a
te dforProcess%d",i
+1)
;temp=temp-mp[
i
];
}
else
{
printf(
"\
nMe mor yisFull
");break;
}
printf(
"\
nDoy ouwa nttoc on t
i
n ue(y
/n)--"
);
sc a
n f(
"%c "
,&c h);
}
printf(
"\
n\nTot alMemor yAv ail
able--%d",ms)
;
printf(
"\
n\n\tPROCESS\ t
\ tMEMORYAL LOCATED" );
for(
i=0;i
<n;
i
++)
print
f("\
n\t%d\ t\t
%d",i
+1,mp[ i
]);
printf(
"\
n\nTot alMemor yAl l
oca t
edis%d",
ms -
temp);
printf(
"\
nTo t
al Exter
nalFragme n t
ati
onis%d",
temp)
;
ge t
c h()
;
}

70
I
NPUT
En
tert
het
ota
lme
mor
yav
ail
abl
e(i
nBy
tes
)-- 1000
En
termemoryre
q u
ir
edforproces
s1(
i
nBy
tes
)-- 400
Memoryi
sal
loca
tedforProces
s1
Doyouwanttocont
inue
(y/n
)-- y
En
termemoryre
q u
ir
edforproces
s2(
i
nBy
tes
)-- 275
Memoryi
sal
loca
tedforProces
s2
Doyouwanttocont
inue
(y/n
)-- y

En
terme
mor
yre
qui
r
edf
orpr
oce
ss3(
i
nBy
tes
)-- 550
OUTPUT
MemoryisF
ull
Tot
alMemor
yAvai
l
abl
e–1000

PROCESS MEMORYAL L
OCATED1
400
2 275

Tot
alMemoryAl
l
ocate
dis675To
tal
Ext
ern
alFr
agment
ati
onis
325

RESULT:
Thust
hepr
ogr
amha
sbe
eni
mpl
eme
nte
dan
dex
ecut
eds
ucc
ess
ful
l
y.

7
1
EX.
NO:
17 SI
MUL
ATI
NGTHECONCEPTOFDI
NI
NG-
PHI
LOSOPHERSPROBLEMDATE:

AI
M
ToWr
i
teaCpr
ogr
amt
osi
mul
at
eth
eco
nce
pto
fDi
ni
ng-
Phi
l
osoph
erspr
obl
em.

DESCRI PTION
Thed i
ni
ng-phil
osopherspr oblemisc on si
de r
e dac l
assi
cs ynch roni
za t
i
o nproblemb ecauseitisa ne xample
ofal ar
gec las
so fc oncurrency-c
on tro
lpro bl
e ms .Itisas implere pre senta
tiono fthen eedtoa llocates evera
l
res
o ur
cesa mongs everalproce
s sesinade a
d l
o ck-fr
e eands t
arv
ation-f
re ema n ner.
Co nsi
derfi
vephilosoph erswho
spendthe i
rli
vesth i
nkinga nde at
ing .Thephi losoph ersshareac i
rc ulartab l
es urr
oundedbyf i
vec hairs,each
bel
ongingtoon eph i
l
osophe r
.Inth ec entero fthet abl
eisabo wlofr i
ce,a ndthet a
bleisl a
idwi thf i
ves in
gle
chopst
icks.Whenaphi losopherthinks,shed oe sn otinter
actwit
hhe rc oll
eague s.
Fromt i
met otime, aph i
losopher
get
sh ungryandtr
iest opickupt hetwoc h
ops ti
c kstha tar
ec l
osesttoh e r(t
hec ho
ps t
i
cksthatarebe twee nhe rand
herlef
ta n
dr i
ghtneighbors).Aphilosopherma ypi ckupo nl
yonec ho ps ti
cka tatime.Ob vi
ously
, s
h ec am1otpi ck
upac hopsti
ckthatisa l
readyi
nt heh ando fan e i
ghb or.Whenah u n
gr yphi l
oso pherhasbothh ercho psti
ck satthe
samet i
me ,sheea t
swi thoutreleasi
n ghe rc hops t
icks.Whe nshei sf inis
he de ati
ng,shepu t
sdo wnb ot
hofh er
chopst
icksands t
artsth i
nki
nga gai
n .Thed i
ning-ph i
losophersproble
mma yleadt oad eadl
ocks i
tuati
o na ndhe nce
somer ul
esh av
etobef r
ame dtoa voidtheoc cur r
en c
eofd ead
lock.

PROGRAM
i
n ttph,philname [20],s
ta t
us [
20],
howhun g,hu[
20],c
ho;
ma i
n (
)
{
i
n ti
; c
lr
s cr(
);
printf
("
\n \nDININGPHI L OSOPHERPROBL EM");
printf
("
\n Enterthet ot
al no.ofphil
os ophers
:");
sc a
n f
("%d",&tph);
for(
i=0;
i<tph;i
++)
{
phil
n ame [i
]=( i
+1) ;st
atus[i]
=1;
}
printf
("
Ho wma nya r
ehun gry:"
);
sc a
n f
("%d",&howhun g);
i
f(howh un g==tph)
{
printf
("
\n Allarehun gry.
.\nDe a
dloc ks t
agewill
occur"
);
pri
n t
f(
"\nEx i
ti
ng..
");
}
else
{
for(
i=0;
i<howhun g;i
++)
{
printf
("
En terph i
l
os ophe r%dpos i
tion :
",
(i
+1))
;scanf
("
%d",&hu[
i
])
;st
atus
[hu[i
]
]=2;
}
do
{
printf
("
1 .
On ec ane atatat ime\t2
.Twoc aneatatati
me \
t3.
Exi
t
\nEn
teryourchoi
ce:
"
);
sc a
n f
("%d",&c ho);
switch(cho)
{
c ase1: one (
);
br eak;
c ase2: two();
br eak;
72
ca se3: exit(0)
;
de fa
ult:pri
n tf(
"\nI
nv al
idopt i
on.
."
);
}
}while(1);
}
}
on e()
{
i
n tpos =0,x ,i;
print
f("\nAllowon ephi l
os ophe rtoe ata ta nyti
me \
n")
;
for(i
=0;i
<howh u ng;i++,pos ++)
{
print
f("\nP%di sgra nt
e dtoe at
",philna
me [hu[pos]
])
;
for(x=pos ;
x< howhun g;
x ++)
print
f("\nP%di swa it
ing",philname [hu[x]]
);
}
}
two( )
{
i
n ti,
j,s=0, t,r,x;
print
f("\nAl lowt wophi los opherst oe ata tsamet i
me\n")
;f
or(
i=
0;i
<howhun
g;i
++)
{
for(j
=i
+1; j
< howhun g;j
++)
{
i
f(abs(hu[ i
]-hu[j])
>=1&&a bs (hu[i
]-hu[j
])!
=4)
{
print
f("\n\nc ombi n
a ti
on%d\ n",(
s +1));t
= hu[i]
;
r=hu[j];s++;
print
f("\nP%da ndP%da r egrantedt oe at",phi
ln
ame [
hu[
i]
],
philname [hu[ j
]])
;
for(x=0;x<howhun g;x++)
{
i
f((hu[x]!
=t)&&( hu[x]!
=r)
)
print
f("\nP%di swa it
ing",philname [hu[x]]
);
}
}
}
}
}
I
NPUT
DI NINGPHI LOSOPHERPROBL EM
En t
erthet ota l
n o.ofphi l
osophe r
s: 5
Howma nya rehun gry: 3
En t
erph i
loso phe r1pos i
ti
on:2
En t
erph i
loso phe r2pos i
ti
on:4
En t
erph i
loso phe r3pos i
ti
on:5
OUTPUT
1On
. ec
ane
ata
tat
i
me
2.
Twocaneata
tatime
3.
Exi
tEn
tery
ourchoi
ce:
1

Al
l
owonephil
osophert
oe a
tatanyt
i
meP3i
sgr
ant
edt
oea
t
P3iswai
ti
ngP5iswa i
t
ingP0iswait
i
ng
P5isgr
ant
edtoe a
tP5iswa i
ti
ng
7
3
P0iswai
ti
ng
P0isgr
ante
dt oeatP0iswa
it
in
g
1.
Onecaneatatatime
2Twoc
. anea ta
tatime
3.
Exi
tEn
teryourchoic
e:2

Al
l
owt
wophi
los
opher
stoeata
ts a
meti
mecombi
nat
i
on1P
3a
ndP5ar
egrant
edtoea
tP0i swai
t
ing

combi
nat
i
on2
P3a n
dP0aregr
ant
edt
oea
tP5i
swa
it
in
g

combi
nat
i
on3
P5a n
dP0aregr
ant
edt
oea
tP3i
swa
it
in
g

1On
. ec
ane
ata
tat
i
me
2.
Twocaneata
tatime
3.
Exi
tEn
tery
ourchoi
ce:
3

RESULT:
Thust
hepr
ogr
amf
orDi
nni
ngPhi
l
osophe
rpr
obl
emha
sbe
ene
xec
ute
dan
dev
alua
teds
ucc
ess
ful
l
y.

74
DESI
GNEXPERI
MENTS
PACMANGAME
AI
M:
Towr
i
teaCpr
ogr
amt
ode
signt
hepa
cma
nga
me.
1.

ALGORI
THM:
STEP1:St
arttheprogr
am
STEP2:Assignthesurf
acev
alu
etoloa
dthei
ma ge
.
STEP3:Assignthea r
gumen
tfort
hema i
nfun
cti
on
STEP4:Ret
u rnt
hev a
lue.
STEP4:St
opt heprogr
am
PROGRAM:

#i
nc l
u de"h eade r.
h"
SDL _Re ctc or={24,25};
i
ntq uit
=n o;
SDL _Su rf
ac e*loa d_i
ma ge (c ha rfi
lename [
])
{
SDL _
Sur face*l oade dIma ge=NUL L;
SDL _Su rface*opt imiz edIma ge=NUL L;
ch arfi
le[]
= "
spr i
tes/";strca t(fi
l
e ,
fi
lename )
;
l
o aded I
ma ge=I MG_ L oa d(f i
le);
i
f(load ed I
ma ge! =NUL L)
{
opti
mi zedIma ge=SDL _Dis pla
y For
ma t(loadedI
ma ge) ;
SDL _F reeSu r
face (loa de dIma ge);
}
returno ptimize dI
ma g e;
}
i
ntma i
n(i
nta r
gc ,char* arg v[])
{
SDL _
Ini
t(SDL _I
NIT_ EVERYTHI NG) ;
SDL _
Sur face*s cre en;
sc r
een =SDL _Se tVideo Mo de (
5 00,
3 50,
32,SDL _SWSURF ACE);
SDL _Su rface*b g =l
o ad_ i
ma ge ("
da r
k.
jpg");
i
n tkey _
pr ess; SDL _WM_ Se tI
c on(I
MG_ Load ("
pacma n_16X16.
png")
,
NUL L);
SDL _WM_ Se tCa ption("Pa c
ma n",
"pa cman_16X1 6.
png")
;
SDL _
Ev e nteve nt;
ex t
ernin tquit;
SDL _Blit
Su rf
a ce(bg ,
NUL L ,
sc r
e en,NUL L
);
ga me pl
a y(screen )
;
return0 ;
}
voi
dpa cma n _s
pr i
tes(SDL _Re c tlocati
on,i
ntd i
recti
on,
SDL _Surf
ace*scre
e n
,charcomp[
20]
[12
])
{
SDL _
Re c tch ar_up,ch ar_d own ,
char_l
eft
,ch ar_
ri
ght,
ch a
r_neut
ral
,c
har_dead ;
ch ar_
up. x=0;c har_up.y= 2 0;cha r_up.
w= 20; char_u
p.h=20;char
_down .
x=20;
ch ar_
do wn .y=2 0;cha r
_ down .w= 20;char_do wn.
h=20 ;c
h ar
_l
eft
.x
=20;
ch ar_
left.
y =0;char_left.
w= 20; cha r
_lef
t.
h=2 0;char_r
ight
.x=40;
char_r
ight
.
y= 0;
ch ar_
right .
w=2 0;cha r_right.h= 20;char_neut r
al.
x=0;
c har
_neutr
al
.y=0
;
ch ar_
n eu tr
al
.w= 20; cha r_n eutral.
h=20;cha r_dead.
x=40;char_
dead.y
=20;
ch ar_
de a d.
w= 20 ;cha r_de ad .
h= 20;SDL _Su rf
ace*on e,
*t
wo ;
on e=l
oa d_ i
ma g e(
"pa cma n .
gif
");
two =l
o ad_ i
ma ge("pac ma n _foll
o w.
g i
f
");i
f
(l
e gi
bil
it
y(c omp, &direction )==y es)
{
75
moveit
(di
rect
i
o n)
;
swit
ch(di
rect
ion
)
{
caseSDL K_UP:
SDL_Bli
tSur
face(
one,&char
_up,
screen,
&l
ocat
ion
);
SDL_Fli
p(scr
een);
break;
caseSDL K_DOWN:
SDL_Bli
tSur
face(
one,&char
_down,sc
reen,
&l
ocati
on)
;SDL_Fl
i
p(scr
een)
;
break;
caseSDL K_RIGHT:SDL_Bli
tSur
face(
one,
&char
_ri
ght,
scr
een,
&l
ocat
ion
);
SDL_Fli
p(scr
een);
break;
caseSDL K_LEFT:SDL _
Bli
tSur
face(
one,
&char_
lef
t,
scr
een,
&l
ocat
ion
);
SDL_Fli
p(scr
een);
break;
}
SDL_De l
ay(7
5);SDL_Bli
tSur
face(
one,
&char_
neutr
al
,sc
reen,
&l
ocat
io
n);
SDL_Fli
p(scr
een);
SDL_De l
ay(7
5);SDL_Bli
tSur
face(
two,
NUL L,
scr
een,
&lo
cati
on)
;
SDL_Fli
p(scr
een);
}
el
se
{
SDL_Bli
tSur
face(
one,&char
_neutr
al
,s
creen,
&l
ocat
ion)
;SDL_Fl
i
p(sc
reen)
;
}
SDL_FreeSurf
ace(on
e);
SDL_FreeSurf
ace(t
wo);
}
v
oidgame pl
ay(SDL _
Su r
fac
e*scre
en)
{
ext
ernintqu i
t
;char
comp[20][
12];
ext
ernSDL _Rectcor;
SDL_Eventevent;i
nt
key_
press;
cr
eatemap(scr
ee n
,comp);
whil
e(qui
t==no)
{
wh i
l
e (
SDL _Pol
lEven
t(&e
vent
))
{

i
f(
event
.
type
==SDL
_QUIT)qu
it
=ye
s;
i
f(ev
ent.
t
ype==
SDL_KEYDOWN)key
_pr
ess
=ev
ent
.
key
.ke
ysy
m.s
ym;
}
pa
cma
n_s
pri
t
es(
cor
,
key
_pr
ess
,sc
ree
n,c
omp)
;
}
}

76
OUTPUT:

RESULT:
Th
ust
hepr
ogr
amf
orpa
cma
nga
meha
sbe
ende
sig
neda
nde
xec
ute
dsuc
ces
sful
l
y.

7
7
CAL
2. ENDARPROGRAM
AIM:
Towr i
teaCpr og ramt oimpl eme n tthec al
e n
d arforpar
tic
ulardat
e.
ALGORI THM:
STEP1: Star
tthepr ogram
STEP2: Readt hev al
uef orda tea sd ay ,
mo n
tha ndy ea
r.
STEP3: Cons t
ru ctthes tructuref ord ate.
STEP4: Returnt hev alue
STEP4 :Stopth epr ogam.
PROGRAM:
#i
nc l
u de<stdi
o.h>
#i
nc l
u de<conio.
h>
#i
nc l
u de
< windows .h>
st
ruc tDa t
e {
i
n tdd;
i
n tmm;
i
n tyy;
};
st
ruc tDa t
ed ate;
st
ruc tRema inder{
i
n tdd; i
nt
mm;
cha rno t
e[50];
};
st
ruc tRe ma i
nderR;
COORDx y={ 0,0} ;
voi
dg ot
ox y(i
ntx ,inty)
{
xy.
X=x ;xy.
Y=y ;
SetCo nsol
e Cu rsorPos i
t
ion (GetSt d
Ha nd l
e(
STD_ OUTPUT_ HANDL E),
xy)
;
}
voi
dSe t
Co l
or
(intF orgC)
{
WORDwCo l
o r;
//Wewi l
lnee dt hish andlet og e tthec urrentba ckgr
ounda tt
ri
bute
HANDL E hSt dOu t = Ge tStdHa n dl
e(STD_ OUTPUT_ HANDL E)
;
CONSOL E_SCREEN_ BUF F ER_ INFOc sbi;
if
(GetCo nsoleSc reenBuffe rI
nfo(hStd Ou t
,&c sbi
))
{
wCol or=( cs bi
.wAttri
bu tes&0x F0)+( ForgC&0x 0F);
SetCon soleTe xtAttr
ibute (
hSt dOut ,wCol or);
}
r
e tur
n ;
}
voi
d
Cle ar
Co lor
()
{Se
tCo l
or(15);
}
voi
dCl ea r
Co nso l
e ToCo l
o r
s (
i
n tF orgC, i
n tBac k
C)
{
WORDwCo lor=((Ba ckC&0 x 0F)<<4)+( ForgC&0x 0F )
;
HANDL Eh StdOu t=Ge tStdHa n dl
e(STD_ OUTPUT_ HANDL E);
COORDc o ord={ 0,0};
DWORDc o u nt
;
CONSOL E_ SCREEN_ BUF FER_ I
NF Oc sbi
;
SetCon sol
e Te xtAtt
ri
b ute(hStd Out ,wCo lor)
;
i
f(GetCo nsol
e Sc reenBuffer
In f
o (
hSt dOu t,&csbi))
{

78
Fi
l
l
Consol
eOut
putCharac
ter
(hStdOut
,(TCHAR)32,c
sbi.
dwSi
ze.
X*cs
bi.
dwSi
ze.
Y,coor
d,&co
unt
);
Fi
l
l
Co n
sol
eOut
putAtt
ri
but
e(hSt
d Out
,csbi
.
wAttr
i
but
es,cs
bi.
dwSi
ze.
X*c
sbi.
dwSi
ze.
Y,co
ord,&c
oun
t);
Set
Consol
eCu
rsorPos
it
ion
(hStdOut
,coord)
;
}
r
etur
n;
}
v
o i
dSe tCo l
orAn dBa ckground(i
ntForgC,i
ntBack
C)
{
WORDwCo lor=( (Ba c
kC&0 x0F)<<4)+(For
gC&0x 0F)
;
Se tCons o
leTex t
At tr
ibute(
Ge t
StdHandl
e(
STD_OUTPUT_HANDLE),wCol
or
);
return;
}
i
ntchec k_l
eapYe ar(
inty ear)
{//checkswh e
thert
heyearpa
ssedi
sle
apy e
arornot
i
f(
ye ar%4 00= =0| |(y
e ar%1 00!
=0&&y ear%4= =
0))
return1 ;
re
turn0 ;
}
v
o i
dinc r
ease_mo n t
h (
int* mm, i
nt*yy)
{
++*mm; i
f(
*mm
>1 2 )
{
++* yy;
*mm=* mm-1 2;
}}
v
o i
dd ec r
ease_ mo nth(i
nt*mm, i
nt*yy
)
{
--
*mm;
i
f(
*mm<1 ){
--*yy;
i
f(*yy<160 0)
{
pri
ntf
("
Nor ecorda vai
labl
e")
;
ret
urn;
}
*mm=* mm+1 2;
}}
i
ntgetNu mbe rOfDa ys(intmo nt
h,i
nt
year){switch(mo nth){
case1: r
eturn(3 1);
case2: i
f
(c heck_l
e apYe ar
(year
)==1)
retur n(
2 9);
else
retur n(
2 8);
case3:r etur
n (31);
case4:r etur
n (30);
case5:r etur
n (31);
case6:r etur
n (30);
case7:r etur
n (31);
case8:r etur
n (31);
case9:r etur
n (30);
case1 0:return(
3 1);
case1 1:return(
3 0);
case1 2:return(31);
default
:return(-
1);
}}
char* getName (i
n t
day){s wit
ch(day )
{
case0: ret
u rn
("Su nda y
");
case1: ret
u rn
("Mo nd ay"
);
case2: ret
u rn
("Tu esd a
y");
case3: ret
u rn
("We dnesday")
;
case4: ret
u rn
("Th ursday")
;
7
9
case5: re t
u rn
("Fr
iday"
);
case6: re t
u rn
("Satur
da y"
);
de f
ault
:r
e turn("
Errori
ng etNa me (
)mo dul
e .
I
nval
i
da r
gumen
tpas
sed")
;
}}
voidprint
_ date(i
ntmm, i
nty y)
{/ /
pri
ntsthen a
meofmon t
handyea
r
pri
ntf(
" -\n"
);
gotoxy(25 ,
6);
switch(mm) {
c a
s e1 :pri
n t
f(
"January");break;
c a
se2 :pri
n t
f(
"February"
);break;
c a
s e3 :pri
n t
f(
"Ma rc
h" )
;break;
c a
s e4 :pri
n t
f(
"Apr i
l
")
; br
e ak;case
5:pr i
ntf(
"Ma y");
break;ca se6 :
printf
("
J un e"
);break;case7:
printf
("
J ul
y ")
;break;case8 :
print
f("
Au g ust")
;break;
c a
s e9 :pri
n t
f(
"Septembe r"
);br
eak;
c a
s e1 0:pr i
nt
f("
Oc tober")
;break;
c a
s e1 1:print
f("
No vemb er"
);break
;
c a
se1 2:print
f("
De cemb er"
);break;
}
pri
ntf
(",%d "
,y y
);
gotoxy(20 ,
7);
pri
ntf(
" -")
;
}
i
ntg etDay Nu mb er
(i
ntda y,
i
n tmo n,
in
tyea r
){//r
etun
sthed
aynumberi
nt
res=0 ,t1 ,t
2, y=y ear;
year=y ea r-1 60 0;
wh i
le(
ye ar
> =10 0)
{
res=r e s+5 ;year
=y ear-100;
}
res=( res%7 )
;
t1=( (
y ear-1 )/4 );
t2=( year-1)-t1;
t1=( t
1*2) +t2;t1
=(t1%7);
res=r es+t 1 ;
res=r es%7 ;
t
2=0;
for(
t1=1; t1<mon ;t
1++){
t2+=ge t
Nu mbe rOfDa ys(t
1,y)
;
}
t2=t 2+d ay;
t2=t 2%7 ;
res=r es+t 2 ;
res=r es%7;
i
f(y>2 000)
res=r e s+1;
res=r es%7;
retur
nr es;
}
c
ha r*getDa y(i
n tdd,i
ntmm, i
n tyy){i
nt
day;
i
f(!
(mm> = 1&&
mm< =12)) {retu
rn("
Inval
id
mo n t
hv alu e
");
}
i
f(!
(dd>=1&&
d d<=getNu mb erOfDa ys(mm, y
y))
){ret
urn("
Inv
ali
d
d a
te "
);
}
80
i
f(y
y>=1600 ){
day=g etDa yNu mber(dd,mm,yy);
day=d ay%7 ;
ret
u r
n(g etNa me (
day))
;
}el
se{
ret
u r
n("Plea seg i
veyea rmo r
et han160
0");
}}
i
ntcheckNot e(intdd ,i
nt
mm) {FILE* fp;
fp=fope n("
n ote.
d at
",
"r
b");
i
f(f
p= =NUL L){
pri
ntf(
"ErrorinOpe ni
ngt hefi
le")
;
}
whil
e(f
read (&R,sizeof(
R),
1 ,
fp)==
1){i
f(R.dd= =dd&&R. mm= =mm) {
fcl
os e(f
p );
return1 ;
}}
f
c l
ose(
fp);
ret
urn0 ;
}
v
o i
dprint
Mo n t
h (i
ntmo n
,i
ntye ar
,i
ntx,
inty)
{
i
ntno d,day, cnt,d=1 ,x1=x ,y1=y ,i
sNot
e=0 ;
i
f(!
(
mon >= 1&&mon <
=12)){
pri
ntf(
"I
NVAL I
DMONTH" )
;
getch()
;
ret
u r
n;
}
i
f(!
(
year>=1 60 0))
{pr i
nt
f(
"I
NVAL I
DYEAR" );
getch()
;
ret
u r
n;
}
gotoxy(
20,y );
pri
nt_dat
e (mo n,year)
;y
+=3;
gotoxy(
x,y);
pri
ntf
("SMTWTFS" )
;y ++;
nod=g e t
Nu mb erOfDays(mo n,
year);
day=g etDa yNu mb er(d
,mon ,y
e a
r);
swit
ch(day )
{/ /locat
esth es t
art
ingdayincal
ende
r
case0:
x=x;
cnt=1 ;
break ;
case1:
x=x+4 ;
cnt=2;
break ;
case2:
x=x+8 ;
cnt=3;
break ;
case3:
x=x+1 2 ;
cnt=4 ;
break ;
case4:
x=x+1 6 ;
8
1
cnt=5
;
break;
c
ase5:
x=x+20;
cnt=6
;
break;
c
ase6:
x=x+24;
cnt
=7;
br
eak;
de
faul
t:
pri
ntf
("
INVAL
IDDATAF
ROMTHEg
etOddNumbe
r()
MODUL
E")
;r
etu
rn;
}
gotoxy (
x,
y )
;
i
f(
cn t==1) {
Se tColor(12);
}
i
f(
ch eckNo te(
d,mon )
==1){SetCol
orAnd
Back gro
un d(
15,12)
;
}
pri
ntf(
"%02 d",
d);
SetCo l
orAn dBa c
kground(1
5,1)
;
for
(d= 2;
d<= nod;
d++){
i
f(cn t
%7 ==0)
{y
++;
cnt=0;
x=x1-4;
}
x=x +4;
cn t
++;
go t
o xy
(x ,
y)
;
i
f(cn t
==1 )
{
SetCo l
or(12);
}else{
ClearCo l
or()
;
}
i
f(che c
k Note(d,
mo n)
==1){SetCol
or
A
ndBa ckgr
o und(
15,1
2 )
;
}
printf
("
%0 2d",d)
;
Se tCol
o rAndBa c
kground(1
5 ,
1)
;
}
got
o xy(8,y+2 )
;
SetCo lor
(14 )
;
pri
ntf(
"Pre ss'
n' t
oNe xt
,Press'p't
oPrev
iousand'
q't
oQui
t"
);
gotoxy (
8,
y +3);
pri
ntf(
"RedBa ckgroun
din di
cat
estheNOTE, Pr
ess'
s'
tos
eenote
:")
;
ClearColo r
();
}
v
oid
AddNo t
e()
{FIL
E*fp;
fp=fopen("
note.
dat
",
"
a b
+")
;
syst
em("cl
s");
gotoxy
(5,
7);
pri
ntf
("
Enterthedat
e(DD/MM):"
);
scanf
("
%d %d",
&R.dd
,&R.mm);
gotoxy
(5,
8);
pri
ntf
("
EntertheNot
e(50char
act
erma
x):
")
;
ff
lu
sh(st
din);
82
scanf(
"%[ ^\n ]
",R.note);
i
f(
fwrit
e(&R, s i
z eof(
R) ,
1,fp)){g ot
oxy(5,12 );
pu t
s("No tei ss aveds uce ssful
ly
");
fcl
os e(fp);
}e
lse{
gotox y(5,12 );
Se t
Co lo r
(1 2);puts("\aF ail
tosa ve !
!
\a ");ClearCo l
or();
}
gotoxy(5,15) ;
pr
intf(
"Pre ssa nyk ey ");
getch()
;
fclose (f
p);
}
vo i
ds h o wNo te(i
n t
mm) {F ILE* f
p;
i
n ti =0 ,i
s Foun d=0 ;
sy stem( "cl
s");
fp=f ope n(
"no te.
d at",
"
rb "
);
i
f(fp= =NUL L)
{
printf
("Errorino peningthefil
e"
);
}
wh il
e (f
read (
&R, size of
(R),1,
f
p)= =
1){if(R.mm= =mm) {
gotoxy (
1 0,5+i);
pri
n t
f("
No te%dDa y=%d :%s",i
+1,R.
dd,R.not
e);
isFoun
d
=1 ;
i
++;
}}
i
f(isFo und= =
0){go t
ox y(
1 0,5)
;
printf
("Th i
sMon thc ont
ainsnon ot
e")
;
}
go tox y(
1 0,
7+i);
printf("
Pr essa n yk eytob ack "
);
ge t
c h();
}
i
n t
ma in(){Cl earCo n sole
To Co l
ors(
1
5, 1);
Se tCo ns ol
eTitl
e ("
Ca len d
erProject-Progra
mmi ng-
techni
que.
bl
ogs
pot
.
com"
);
int
cho ice;
cha rc h=' a';
wh il
e (1){
sys tem("cls");
printf
("1.FindOutt heDa y\n"
);pri
nt
f("
2.
Printa l
ltheda yo fmo nt
h\n")
;pri
ntf
("
3.
Ad dNo te\n ")
;
printf
("4.EXI T\ n")
;
printf
("ENTERYOURCHOI CE: ")
;
sca nf(
"%d ",
&c ho i
ce);
sys tem("cls");
swi t
c h(choice )
{
cas e1 :
pr i
ntf(
"En terda te(DDMMYYYY): ");
scanf
("
%d%d
%d ",
&d a t
e .
dd,&d at
e.
mm, &date
.yy)
;
pr i
ntf
("Da yi s:%s ",
get
Da y(
date.
dd,
date.
mm,dat
e .
yy
));
pr i
ntf(
"\n Pressa nyk eytoconti
nue " )
;
g etch();
8
3
bre
ak;
ca
s e2:
pri
nt
f(
"Entermo nt
ha ndy ear(MMYYYY): "
);
scanf
("
%d%d" ,
&dat
e .
mm, &date.y
y);sy
stem(
"cl
s"
);
whil
e(
ch!='
q')
{pri
ntMo nt
h(date.
mm, dat
e.
yy,
20,
5);ch=g etch()
;
i
f(
ch= ='n'
){i
ncrease_mon t
h(&date.
mm,&dat
e.
yy)
;
syst
e m("c
ls"
);
pri
ntMon t
h(d
ate.mm,da t
e.yy,
20,
5);
}el
seif
(ch= =
'
p')
{d ecr
ease_mo nt
h (
&date.
mm, &dat
e.
yy)
;
syst
e m("c
ls"
);pr
int
Mon th(dat
e.mm,dat
e.
yy,
20,
5);
}el
seif
(ch= =
'
s'
){sh o
wNo te(d
a t
e.
m
m);system("
cls"
);
}}
bre
ak;
ca
s e3:
AddNote()
;
bre
ak;
ca
s e4:
exi
t(
0);
}}
r
eturn0;
}

OUTPUT:

84
RESULT:
Thusth
epr
ogr
amt
odi
spl
ayt
hec
ale
nda
rofpa
rti
cul
arda
teha
sbe
ene
xec
ute
dan
dve
ri
fi
eds
ucc
ess
ful
l
y.

8
5
OPENENDEDPROBLEMS

1.I
MPL
EMENTAPROPORTI
ONAL
-SHARESCHEDULER

AI
M:
Towr
i
teapr
ogr
amt
oimpl
eme
ntapr
opot
i
ona
lsha
res
che
dul
er
.

PROBLEMSTATEMENT:
Aswediscus s
edinc l
ass,recentv ers
io nsofL i
nuxha vemov e
da wa yfr
omt hetradit
i
o nalMLFQS- de r
i
v edd esi
gn
andchose
naWF Q- d er
i
v edde si
gn ,the" completel
yf ai
rschedul
er"(CF S).Impleme ntav ari
an tofpr oporti
onal
shar
escheduli
ngfo rPintos.Di
fferenta pproachesa r
epos si
ble,i
ncl
udingb utnotlimit
edt o:
 Impl eme ntL otter
ySc he duli
ng .Lot
terySc hedul
ingisdesc r
i
b edh ere.Un l
i
ket heBSDs c
h edu l
eryou
i
mpl eme ntedinpr oject1 ,stri
ctproport
ionalshareschedu l
ersd on ota t
temptt oprov i
depr efer
e nc
e
forI/Ob ou ndpr oce
s ses.
 Impl eme ntStri
d eSch eduli
ng. Str
i
d eschedu l
i
ngisad et
erminist
icva r
i
an tofwe i
ghted-f
a i
rque i
n g.
 Impl eme ntL i
nux '
sCo mple t
elyF ai
rSched ul
er,orCFSa l
gorit
hm.
 T hecu r
ren tPintosk e
rn elus essa mpli
ngt oesti
ma t
eapr ocess'
spa s tCPUu sage. Mod e
r nkernels
ex pl
oi
tt i
me s
tampc oun t
e r
st omo r
ea ccuratel
yme asureapr ocess'
sCPUu sa
ge .Fo re xample,
Wi ndowsVi s
tai nt
roduc e
dt hisc hangef ortheMSWi ndowsl i
n eofk ernel
s .
Inpa r
ti
c ul
ar,theus eof
ti
me stampc oun t
ersa l
lowso net oe xc
ludet i
mes penth andl
ingi n
terrupt
s ,whichs houldn otc ount
ag ai
nstthec urr
entpro cess. Thi
sc hanger equir
esidenti
fyi
nga ndi mpleme nti
ngthen eede dAPI s.I
t
co ul
db ed onei nconjunctionwi t
ho neofth eschedul
erpro j
ects.

2. ANAL
YZEVMPAGEREPLACEMENTPOL
ICI
ES

AI
M:

Towr
i
teapr
ogr
amt
oal
al
yzeVMpa
ger
epl
ace
men
tpol
i
ci
es.

PROBLEMSTATEMENT:

Imple
me ntmult
i
pledi
ff
ere
ntr
epl
ace
me ntpo
li
ci
esandan
alyzet
hei
rbenef
i
tsf
ordi
ff
eren
twor
kl
oads.
Mos
tofyou
wil
lpr
obablyj
ustimpl
ements
omev er
si
onofa1-bi
tor2-bi
tcl
ock
.Thi
swoul
dinv
olv
eimpl
ement
i
ngavari
et
yof
cache
-re
place
me ntpol
i
ci
esanda
nal
yzi
ngthei
rper
for
mance.

F
ori
ttobeve r
yrea
li
st
ic,y
ouwoul
dh av
et oi
mplementauni
fi
edbuf
fercac
he/pagecac
heCu r
rent
l
y,Pint
oshas
s
epar
atebuf
fercache
sa ndVMcaches.Thi
sme an
st hats
har
edma ppi
ngso ff
i
lesar
en'tsuppor
ted,andt
hat
s
epar
ateevi
cti
onpol
i
ciesarei
nef
fec
t.RealOSme r
get het
wo;af
teral
l
,phys
ical
me morycouldbeus e
de i
t
her
f
orf
i
lecac
hing,f
i
leahe
ad,orpr
ogr
am'sdataorc
ode.

I
fauni
fi
edb
uff
erc
acheisi
mpleme
nte
d,c
oul
dloo
katt
hepe
rfor
man
ceo
fal
gor
i
thmsl
i
ket
heon
eus
edi
nLi
nux
,
ormor
emoder
nal
gori
t
hmss u
chasARC.

86
3.I
MPL
EMENTADVANCEDF
ILESYSTEMF
EATURES

AI
M:
Towr
i
teapr
ogr
amt
oimpl
eme
nta
dva
nce
dfi
l
esy
ste
mfe
atur
es.

PROBLEMSTATEMENT:
 Mo dernfi
l
es ystemsha v ema nyadv ancedf eat
uressucha s.
 As cal
abledirect
oryimpl eme ntat
ion, per
hapsus i
ngB- t
rees.
 Re coveryafterac rash.Eit
h ertradi
ti
on alf
sck,orsomev ersi
onofphysi
call
og gi
ng.
 Va ri
ousot h
e rideasI haven'tthough tmu chabou t
.
 Impleme nta ccesst ogr aphicsorot he rhardwa r
ePr ovidea c
cesst othef ramebuf ferto
appli
cati
ons( easytod o),and/ orprovid esupportforl
ow- r
e s
olut
i
ong r
aphics,e.
g.VESA.Por ta
graphi
cal l
i
braryforu seb yapplicat
ions .Moreadvancedwo ul
dbea ccesstoar ece
ntg e
n e
rati
on
graphi
csc ard.
 Impleme ntsharedme mor yImpl eme nts omek i
ndo fsha
r e
dme moryfac
il
i
ty,suchasmma p(
)with
MAP_ SHARED. Shari
ngs houldb es upportedthroughouttheVMs y
stem,incl
udi
ng,fori
nstance
,
shari
ngofr ead-on l
yc odes e
gme ntpa ges.Yourpa gee v
ict
ionpoli
cymus tt
a keshar
e dme mory
in
toa ccount.

4.I
MPLEMENTUNI
X-STYL
EPROCESSESANDF
ILEDESCRI
PTORS,
ALONGWI
THPI
PES

AI
M:
Towr
i
teapr
ogr
amt
oimpl
eme
ntu
nix
-st
yl
epr
oce
sse
san
dfi
l
ede
scr
i
ptor
s,a
lon
gwi
t
hpi
pes
.

PROBL EMSTATEMENT:
Pintosuse sas i
mpl i
fi
edpr ocessmo delthatrepresen t
sami xt
ureo fWi ndowsa ndUni
x:Li
keinWi ndows ,
ex
ec()create
sb ot
han ewpr ocessa n
dl oadsan ewpr og r
a m.LikeinUn ix,t
he r
eisawa i
t(
)faci
li
t
ytowa i
tfor
t
ermi
n at
ingc hi
ldren.InPin t
os,fi
lede scri
ptorsa r
ec urr
e ntl
yn ots har
e dbe t
we e
npr oc
essesa nda ren ot
i
nher
i
te dwh enac hi
ldpr ocessisc reat
e d.Asar esult,i
tisn otpo s
s i
bl
et oi mplementUni
x-st
yleredir
ec t
i
on .
I
mple
me ntaUn ix-
styl
emo deli
nPin t
o s!Thiswo ul
de ntail
:
 Ma kingfi
led e scr
ipt
o rssh a
rea bl
e( an dre f
erenc ec ounted)s oth atag i
venf i
l
ed escr
i
ptorc ouldbe
referr
edtof rommo ret ha
no n eproc ess.Rightn ow, yourfi
lede s
criptorsareprobabl
yemb eddedi nthe
o wningpr ocess'sfil
ede scri
pto rt a
b l
e.Th i
sn eedst ober epl
ac edwi thd ynami
cal
lyall
ocatedd a t
a
structur
es, whicha l
somu stbepr o te
c t
eda gainstcon curre
n taccesse s.
 Addn ecess a
rys ystemc all
stoa l
l
ows h a
ringoff i
led escri
ptorsac rosspro c
esses:f
ork(
),aUn ix
-s tyl
e
e xec_i
n_proce ss,
dup( ),
dup2( )
.
 Impl eme ntpipe()
 Impl eme ntUs erMe mo r
yAl l
oca t
ion/sbrk(
).Cu rrent
ly,Pintosdo esn otsupportmall
oc(
)forus er-level
pro gr
amsb ecau s
ei tdo esn ots uppo rtagr owingh eap.Impleme n tsbrk(
)a ndadoptyourCS32 14
me mo ryallocat
ort oprovidema l
loc()tou sermod epr ocesses.Th i
swi l
lb enecess
aryforyourpor ti
ng
yo urshel
l.
 Impl eme ntas hell
(couldb esi
mpl if
iedv ers
iono fyo urCS32 14s hel
l)

8
7
I
MPLEMENTNETWORKI
NG
AI
M:
5. Towr
i
teapr
ogr
amt
oimpl
eme
ntn
etwor
ki
ngc
onc
epti
nli
nux
.

PROBL EMSTATEMENT:
Asis,Pint
osd oesnotprovi
des upportfornetwor
ki
ng.Ho we v
er,ourv ersi
ondo eshaves uppor
tfor
PCI.Thi
sc onceptinv
olveswri
ti
nga nEthe r
netdr i
verandhookin
gi tupt oan etworki
ngs t
ack.Apo ssi
ble
approa
chma ybe :
o Ami ni
mum f unct
i
onal
it
yd ev
iced ri
ver
,fortheE1000ca r
d. Thi
sisu s e
dint henetworkla
bi nMIT'
s
JOSpr oj
ect.TheE1000isac omplexca r
d ,
butonl
yasub setoffeaturesisneededtogetawor ki
ng
st
ack.Wewo ul
drelyontheca r
d'semu la
ti
oninqemu.Th i
sme ansy oucand ebugitwit
hac ust
om
bui
l
do fqemu .
o Ad aptthelwI
Ps tac
k,pr
o v
idedh er
e.Thi
si sagener
icI
Ps tacktar
g etedforembe ddabi
l
i
ty.
o Impleme ntthemini
mumr equiredfunct
ional
it
ytoprov
ides upportforsockets.Achi
evethea bi
l
i
tyto
l
ogintoPint
osv i
atel
net
!
Thi
swo uldb eapr oj
e c
tforanyonewa nti
ngt olearnmorea boutde vi
ced riv
ersa swe l
lasho wak er
nel
i
mpleme n
tsnetworki
ng.

88

You might also like