Su!e"t# $%&' S(ste) P*+,*-))&%, Su.C+/e#
The major diferences between ANSI C and K&R C [Kernighan and Ritchie] are
as follows
!"nction #rotot$#ing
S"##ort of the const and %olatile data t$#e &"ali'ers(
S"##ort wide characters and internationali)ation(
*ermit f"nction #ointers to be "sed witho"t dereferencing(
Fu%"t&+% p*+t+t(p&%,
ANSI C ado#ts C++ f"nction #rotot$#e techni&"e where f"nction
de'nition and declaration incl"de f"nction names,arg"ments- data t$#es,
and ret"rn %al"e data t$#es( This enables ANSI C com#ilers to chec. for
f"nction calls in "ser#rograms that #ass in%alid n"mber of arg"ments or
incom#atible arg"ments- data t$#e(These '/ a major wea.ness of K&R C
com#ilers in%alid f"nction calls in "ser #rograms often #ass com#ilation b"t
ca"se #rograms to crash when the$ are e/ec"ted(
/-t--t(pe 2u%"t&+%-%-)e 3/-t- t(pe
p-*-)ete* %-)e,44444444..5

E'# &%t 213&%t - , &%t 56
78R C #
/-t--t(pe 2u%"t&+%-%-)e 3p-*-)ete*
E9# &%t 213- , 56
&%t -, 6
Supp+*t +2 t:e "+%st -%/ ;+<-t&<e /-t- t(pe =u-<&>e*s.
0 *resent in ANSI C not in K&R C
0 const1im#lies data cant be changed
20here #rintf cant change the
%al"e of / 02
int #rintf3const char0 /,4(5
8olatile .e$word s#eci'es that the %al"es of some %ariables ma$ change
as$nchrono"sl$, gi%ing an hint to the com#iler-s o#timi)ation algorithm not
to remo%e an$ 9red"ndant: statements that in%ol%e 9%olatile: objects(
char get;io35
%olatile char0 io;#ort < =/>>>>?
char ch < 0io;#ort? 20read 'rst b$te of data02
ch < 0io;#ort? 20read second b$te of data02
If io;#ort %ariable is not declared to be %olatile when the #rogram is
com#iled, the com#iler ma$ eliminate second ch < 0io;#ort statement, as it
is considered red"ndant with res#ect to the #re%io"s statement(
Supp+*t ?&/e ":-*-"te*s -%/ &%te*%-t&+%-<&@-t&+%.
ANSI C s"##orts internationalisation b$ allowing C1#rogram to "se wide
characters( @ide characters "se more than one b$te of storage #er
 ANSI C de'nes the setlocale f"nction, which allows "sers to s#ecif$ the
format of date, monetar$ and real n"mber re#resentations(
 !or eg most co"ntries dis#la$ the date in dd2mm2$$$$ format whereas
AS dis#la$s it in mm2dd2$$$$ format(
 !"nction #rotot$#e of setlocale f"nction is
#include <locale.h>
Char setlocale (int category, const char* locale);
 The setlocale f"nction #rotot$#e and #ossible %al"es of the categor$
arg"ment are declared in the Blocale(hC header( The categor$ %al"es
s#ecif$ what format class3es5 is to be changed(
 Some of the #ossible %al"es of the categor$ arg"ment are
Pe*)&t 2u%"t&+% p+&%te*s t+ e use/ ?&t:+ut /e*e2e*e%"&%,
 ANSI C Da f"nction #ointer can be "sed li.e a f"nction
 K&R C D re&"ires the #ointer to be de referenced to call the f"nction
A&%"<u/e Bst/&+.:C
;+&/ s-)p<eD&%t3&%t '5
p*&%t23F9 &s G/H,'56
&%t )-&%35
;+&/ 3J2pt*53&%t56
2pt*3056 LL-<<+?e/ &% A%s& " 3J2pt*5305 6 LL &% 78R "
2pt*3556 3J2pt*53556
*etu*% 06
The general 'le attrib"tes for each 'le in a 'le s$stem are
In addition to the abo%e attrib"tes, ANIE s$stems also store the major and
minor de%ice n"mbers for each de%ice 'le( All the abo%e attrib"tes are
assigned b$ the .ernel to a 'le when it is created(
The attrib"tes that are constant for an$ 'le are
 !ile t$#e
 !ile inode n"mber
 !ile s$stem IF
 Gajor and minor de%ice n"mber
The other attrib"tes are changed b$ the following ANIE commands or s$stem
ANIE command S$stem call Attrib"tes changed
chmod chmod Changes access #ermission, last change time
chown chown Changes AIF, last change time
chgr# chown Changes HIF, last change time
To"ch "time Changes last access time, modi'cation time
ln lin. Increases hard lin. co"nt
rm "nlin. Fecreases hard lin. co"nt( If the hard lin.
co"nt is )ero, the 'le will be
remo%ed from the 'le s$stem
%i, emac Changes the 'le si)e, last access time, last
modi'cation time
A 'le in a ANIE or *ISIE s$stem ma$ be one of the following t$#es
J( Reg"lar 'le
K( Firector$ 'le
L( !I!I 'le
M( Fe%ice 'le
N( Oin. !ile
Re,u<-* ><e
 A reg"lar 'le ma$ be either a te/t 'le or a binar$ 'le
 These 'les ma$ be read or written to b$ "sers with the a##ro#riate
access #ermission
 Reg"lar 'les ma$ be created, browsed thro"gh and modi'ed b$
%ario"s means s"ch as te/t editors or com#ilers, and the$ can be
remo%ed b$ s#eci'c s$stem commands
D&*e"t+*( ><e
 It is li.e a folder that contains other 'les, incl"ding s"b1director$ 'les(
 It #ro%ides a means for "sers to organise their 'les into some
hierarchical str"ct"re based on 'le relationshi# or "ses(
P/ 2bin director$ contains all s$stem e/ec"table #rograms, s"ch as
cat, rm, sort
A director$ ma$ be created in ANIE b$ the m.dir command
P/ m.dir 2"sr2foo2/$)
A director$ ma$ be remo%ed %ia the rmdir command
P/ rmdir 2"sr2foo2/$)
The content of director$ ma$ be dis#la$ed b$ the ls command
De;&"e ><e
Qloc. de%ice 'le
*h$sical de%ice which transmits data a bloc. at a time
PE hard dis. dri%e, Ro##$ dis. dri%e
Character de%ice 'le
*h$sical de%ice which transmits data in a character1based manner
PE line #rinters, modems, consoles
A #h$sical de%ice ma$ ha%e both bloc. and character de%ice 'les
re#resenting it for diferent access methods( An a##lication #rogram ma$
#erform read and write o#erations on a de%ice 'le and the IS will
a"tomaticall$ in%o.e an a##ro#riate de%ice dri%er f"nction to #erform the
act"al data transfer between the #h$sical de%ice and the a##lication
An a##lication #rogram in t"rn ma$ choose to transfer data b$ either a
character1based3%ia character de%ice 'le5 or bloc.1based3%ia bloc. de%ice
A de%ice 'le is created in ANIE %ia the m.nod command
Sere , c 1 character de%ice 'le JJN 1 major de%ice n"mber N 1 minor de%ice n"mber
F+* <+"M /e;&"e ><e, use -*,u)e%t NO &%ste-/ +2 N"O.
Gajor de%ice n"mber 1 an inde/ to a .ernel table that contains the addresses
of all de%ice dri%er f"nctions .nown to the s$stem( @hene%er a #rocess
reads data from or writes data to a de%ice 'le, the .ernel "ses the
de%ice 'le-s major n"mber to select and in%o.e a de%ice dri%er f"nction
to carr$ o"tact"al data transfer with a #h$sical de%ice(
Ginor de%ice n"mber 1 an integer %al"e to be #assed as an arg"ment to a
de%ice dri%er f"nction when it is called( It tells the de%ice dri%er f"nction
what act"al #h$sical de%ice is to and the I2I b"fering scheme to
be "sed for data transfer(
FIFO ><e
• It is a s#ecial #i#e de%ice 'le which #ro%ides a tem#orar$ b"fer for
two or more #rocesses to comm"nicate b$ writing data to and
reading data from the b"fer(
• The si)e of the b"fer is '/ed to *I*P;QA!(
• Fata in the b"fer is accessed in a 'rst1in1'rst1o"t manner(
• The b"fer is allocated when the 'rst #rocess o#ens the !I!I 'le for
read or write(
• The b"fer is discarded when all #rocesses close their references
3stream #ointers5 to the !I!I 'le(
• Fata stored in a !I!I b"fer is tem#orar$(
• A !I!I 'le ma$ be created %ia the m.'fo command(
The following command creates a !I!I 'le 3if it does not e/ists5
m.'fo 2"sr2#rog2'fo;#i#e
The following command creates a !I!I 'le 3if it does not e/ists5
m.nod2"sr2#rog2'fo;#i#e #
!I!I 'les can be remo%ed "sing rm command(
S()+<&" <&%M ><e
J( QSF ANIE & S8M de'nes a s$mbolic lin. 'le(
K( A s$mbolic lin. 'le contains a #ath name which references another 'le
in either local or a remote 'le s$stem(
L( *ISIE(J does not s"##ort s$mbolic lin. 'le t$#e
M( A s$mbolic lin. ma$ be created in ANIE %ia the ln command
P/ ln 1s 2"sr2di%$a2original 2"sr2raj2slin.
N( It is #ossible to create a s$mbolic lin. to reference another s$mbolic
T( rm, m% and chmod commands will o#erate onl$ on the s$mbolic lin.
arg"ments directl$ and not on the 'les that the$ reference(
To ens"re a "ser #rogram conforms to *ISIE(J standard, the "ser sho"ld
either de'ne the manifested constant ;*ISIE;SIARCP at the beginning of
each so"rce mod"le of the #rogram 3before incl"sion of an$ header5 as?
Ir s#ecif$ the 1F;*ISIE;SIARCP o#tion to a C++ com#iler 3CC5 in a
*rogram to chec. and dis#la$ ;*ISIE;8PRSIIN constant of the s$stem on
which it r"ns
int main35
co"tBB9S$stem conforms to *ISIE:BB9;*ISIE;8PRSIINBBendl?
co"tBB9;*ISIE;8PRSIIN "nde'nedXn:?
ret"rn =?
• The read f"nction fetches a '/ed si)e of bloc. of data from a 'le
referenced b$ a gi%en 'le descri#tor(
• The #rotot$#e of read f"nction is
• If s"ccessf"l, read ret"rns the n"mber of b$tes act"all$ read(
• If "ns"ccessf"l, read ret"rns DJ(
• The 'rst arg"ment is an integer, fdesc that refers to an o#ened 'le(
• The second arg"ment, b"f is the address of a b"fer holding an$ data
• The third arg"ment s#eci'es how man$ b$tes of data are to be read
from the 'le(
• The si)e;t data t$#e is de'ned in the Bs$s2t$#es(hC header and
sho"ld be the same as "nsigned int(
• There are se%eral cases in which the n"mber of b$tes act"all$ read is
less than the amo"nt re&"ested
• @hen reading from a reg"lar 'le, if the end of 'le is reached before
the re&"ested n"mber of b$tes has been read( !or e/am#le, if L=
b$tes remain "ntil the end of 'le and we tr$ to read J== b$tes,
read ret"rns L=( The ne/t time we call read, it will ret"rn = 3end of
• @hen reading from a terminal de%ice( Normall$, "# to one line is
read at a time(
• @hen reading from a networ.( Q"fering within the networ. ma$
ca"se less than the re&"ested amo"nt to be ret"rned(
• @hen reading from a #i#e or !I!I( If the #i#e contains fewer b$tes
than re&"ested, read will ret"rn onl$
what is a%ailable(
*ISIE(J de'nes a set of feat"re test macro-s which if de'ned on a s$stem,
means that the s$stem has im#lemented the corres#onding feat"res( All
these test macros are de'ned in Bu%&st/.:C header(
Fe-tu*e test )-"*+ EPe"ts &2 /e>%e/
DPOSI9DQOBDCONTROL The s$stem s"##orts the QSF st$le job
DPOSI9DSAREDDIDS Pach #rocess r"nning on the s$stem
.ee#s the sa%ed set AIF and the set1
HIF, so that the$ can change its
efecti%e "ser1IF and gro"#1IF to those
%al"es %ia sete"id and setegid A*IZs(
DPOSI9DCSOTNDRESTRICTED If the de'ned %al"e is 1J, "sers ma$
change ownershi# of 'les owned b$
them, otherwise onl$ "sers with s#ecial
#ri%ilege ma$ change ownershi# of an$
'le on the s$stem(
DPOSI9DNODTR$NC If the de'ned %al"e is 1J, an$ long
#athname #assed to an A*I is silentl$
tr"ncated to NAGP;GAE b$tes,
otherwise error is generated(
DPOSI9DRDISABLE If de'ned %al"e is 1J, there is no
disabling character for s#ecial
characters for all terminal de%ice 'les(
Itherwise the %al"e is the disabling
character %al"e(
L&)&ts ":e"M&%, -t C+)p&<e t&)e -%/ -t Ru% t&)e
*ISIE(J and *ISIE(Jb de'nes a set of s$stem con'g"ration limits in the form
of manifested constants in the Blimits(hC header(
T:e 2+<<+?&%, &s - <&st +2 POSI9.1 – /e>%e/ "+%st-%ts &% t:e
B<&)&ts.:C :e-/e*.
Com#ile time limit Gin( 8al"e Geaning
DPOSI9DCSILDDMA9 T Ga/im"m n"mber of
child #rocesses that
ma$ be created at an$
one time b$ a #rocess(
DPOSI9DOPENDMA9 JT Ga/im"m n"mber of
'les that a #rocess can
o#en sim"ltaneo"sl$(
[ Ga/im"m n"mber of
I2I streams o#ened b$
a #rocess
DPOSI9DARGDMA9 M=WT Ga/im"m si)e, in
b$tes of arg"ments
that ma$ be #assed to
an exec f"nction(
= Ga/im"m n"mber of
s"##lemental gro"#s
to which a #rocess
ma$ belong
DPOSI9DPATSDMA9 KNN Ga/im"m n"mber of
characters allowed in a
#ath name
DPOSI9DNAMEDMA9 JM Ga/im"m n"mber of
characters allowed in a
'le name
DPOSI9DLIN7DMA9 [ Ga/im"m n"mber of
lin.s a 'le ma$ ha%e
DPOSI9DPIPEDB$F NJK Ga/im"m si)e of a
bloc. of data that ma$
be atomicall$ read
from or written to a
DPOSI9DMA9DINP$T KNN Ga/im"m ca#acit$ of a
terminal-s in#"t &"e"e
DPOSI9DMA9DCANON KNN Ga/im"m si)e of a
terminal-s canonical
in#"t &"e"e
DPOSI9DSSIUEDMA9 LK>T> Ga/im"m %al"e that
can be stored in a
ssi)e;t1t$#ed object
L Ga/im"m n"mber of
characters in a time
)one name
T:e 2+<<+?&%, &s - <&st +2 POSI9.1 – /e>%e/ "+%st-%ts#
Com#ile time limit Gin( 8al"e Geaning
DPOSI9DAIODMA9 J N"mber of sim"ltaneo"s
as$nchrono"s I2I(
K Ga/im"m n"mber of
o#erations in one listio(
DPOSI9DTIMERDMA9 LK Ga/im"m n"mber of
timers that can be "sed
sim"ltaneo"sl$ b$ a
LK Ga/im"m n"mber of
o%err"ns allowed #er
DPOSI9DM1DOPENDMA9 K Ga/im"m n"mber of
message &"e"es that
ma$ be accessed
sim"ltaneo"sl$ #er
DPOSI9DM1DPRIODMA9 K Ga/im"m n"mber of
message #riorities that
can be assigned to the
DPOSI9DRTSIGDMA9 [ Ga/im"m n"mber of real
time signals(
LK Ga/im"m n"mber of real
time signals that a
#rocess ma$ &"e"e at
an$ time(
KNT Ga/im"m n"mber of
sema#hores that ma$ be
"sed sim"ltaneo"sl$ #er
LK>T> Ga/im"m %al"e that ma$
be assigned to a
In ANIE s$stem 8, the .ernel maintains a 'le table that has an entr$ of
all o#ened 'les and also there is an inode table that contains a co#$ of 'le
inodes that are most recentl$ accessed( A #rocess, which gets created when
a command is e/ec"ted will be ha%ing its own data s#ace 3data str"ct"re5
wherein it will be ha%ing 'le descri#tor table( The 'le descri#tor table will be
ha%ing an ma/im"m of I*PN;GAE 'le entries( @hene%er the #rocess calls
the +pe% f"nction to o#en a 'le to read or write, the .ernel will resol%e the
#athname to the 'le inode n"mber( The ste#s in%ol%ed are
J( The .ernel will search the #rocess descri#tor table and loo. for the
'rst "n"sed entr$( If an entr$ is fo"nd, that entr$ will be designated to
reference the 'le (The inde/ of the entr$ will be ret"rned to the #rocess
as the 'le descri#tor of the o#ened 'le(
K( The .ernel will scan the 'le table in its .ernel s#ace to 'nd an
"n"sed entr$ that can be assigned to reference the 'le( If an "n"sed
entr$ is fo"nd the following e%ents will occ"r
• The #rocess 'le descri#tor table entr$ will be set to #oint to this
'le table entr$(
• The 'le table entr$ will be set to #oint to the inode table entr$,
where the inode record of the 'le is stored(
• The 'le table entr$ will contain the c"rrent 'le #ointer of the
o#en 'le( This is an ofset from the beginning of the 'le where
the ne/t read or write will occ"r(
• The 'le table entr$ will contain an o#en mode that s#eci'es that
the 'le o#ened is for read onl$, write onl$ or read and write etc(
This sho"ld be s#eci'ed in o#en f"nction call(
• The reference co"nt 3rc5 in the 'le table entr$ is set to J(
Reference co"nt is "sed to .ee# trac. of how man$ 'le
descri#tors from an$ #rocess are referring the entr$(
• The reference co"nt of the in1memor$ inode of the 'le is
increased b$ J( This co"nt s#eci'es how man$ 'le table entries
are #ointing to that inode(
If either 3J5 or 3K5 fails, the +pe% s$stem call ret"rns 1J 3fail"re2error5
Normall$ the reference co"nt in the 'le table entr$ is J,if we wish to increase
the rc in the 'le table entr$, this can be done "sing for.,d"#,d"#K s$stem
call( @hen a o#en s$stem call is s"cceeded, its ret"rn %al"e will be an integer
3'ledescri#tor5( @hene%er the #rocess wants to read or write data from the
'le, it sho"ld "se the 'le descri#tor as one of its arg"ment(
The following e%ents will occ"r whene%er a #rocess calls the "<+se
f"nction to close the 'les that are o#ened(
J( The .ernel sets the corres#onding 'le descri#tor table entr$ to be
K( It decrements the rc in the corres#onding 'le table entr$ b$ J, if rc
not e&"al to = go to ste# T(
L( The 'le table entr$ is mar.ed as "n"sed(
M( The rc in the corres#onding 'le inode table entr$ is decremented b$
J, if rc %al"e not e&"al to = go to ste# T(
N( If the hard lin. co"nt of the inode is not )ero, it ret"rns to the caller
with a s"ccess stat"s otherwise it mar.s the inode table entr$ as
"n"sed and de1allocates all the #h$sical d"s. storage of the 'le(
T( It ret"rns to the #rocess with a = 3s"ccess5 stat"s(
This is "sed to establish a connection between a #rocess and a 'le i(e( it is
"sed to o#en an e/isting 'le for data transfer f"nction or else it ma$ be also
be "sed to create a new 'le(
 The ret"rned %al"e of the o#en s$stem call is the 'le descri#tor 3row
n"mber of the 'le table5, which contains the inode information(
 The #rotot$#e of o#en f"nction is
 If s"ccessf"l, o#en ret"rns a nonnegati%e integer re#resenting the
o#en 'le descri#tor(
 If "ns"ccessf"l, o#en ret"rns DJ(
 The 'rst arg"ment is the name of the 'le to be created or o#ened( This
ma$ be an absol"te #athname or relati%e #athname(
 If the gi%en #athname is s$mbolic lin., the o#en f"nction will resol%e
the s$mbolic lin. reference to a non s$mbolic lin. 'le to which it refers(
 The second arg"ment is access modes, which is an integer %al"e that
s#eci'es how act"all$ the 'le sho"ld be accessed b$ the calling
 Henerall$ the access modes are s#eci'ed in Bfcntl(hC( 8ario"s access
modes are
ODRDONLV 1 o#en for reading 'le onl$
ODTRONLV 1 o#en for writing 'le onl$
ODRDTR 1 o#ens for reading and writing 'le(
There are other access modes, which are termed as access modi'er Rags,
and one or more of the following can be s#eci'ed b$ bitwise1IRing them
with one of the abo%e access mode Rags to alter the access mechanism of
the 'le(
ODAPPEND 1 A##end data to the end of 'le(
ODCREAT 1 Create the 'le if it doesn-t e/ist
ODE9CL 1 Henerate an error if I;CRPAT is also s#eci'ed and the 'le
alread$ e/ists(
ODTR$NC 1 If 'le e/ists discard the 'le content and set the 'le si)e to
)ero b$tes(
ODNONBLOC7 1 S#ecif$ s"bse&"ent read or write on the 'le sho"ld
ODNOCTTV 1 S#ecif$ not to "se terminal de%ice 'le as the calling
#rocess control terminal(
To ill"strate the "se of the abo%e Rags, the following e/am#le statement
o#ens a 'le called 2"sr2di%$a2"s# for read and write in a##end mode
&%t 2/K+pe%3FLus*L/&;(-LuspH,ODRDTR Y ODAPPEND,056
 If the 'le is o#ened in read onl$, then no other modi'er Rags can be "sed(
 If a 'le is o#ened in write onl$ or read write, then we are allowed to "se
an$ modi'er Rags along with them(
 The third arg"ment is "sed onl$ when a new 'le is being created( The
s$mbolic names for 'le #ermission are gi%en in the table
a5Sard and S$mbolic Oin.s
 A hard lin. is a ANIE #athname for a 'le( Henerall$ most of the ANIE 'les
will be ha%ing onl$ one hard lin.(
 In order to create a hard lin., we "se the command <%(
P/am#le Consider a 'le 2"sr2 di%$a2old, to this we can create a hard
lin. b$
<% Lus*L /&;(-L+</ Lus*L /&;(-L%e?
after this we can refer the 'le b$ either 2"sr2 di%$a2old or 2"sr2
 S$mbolic lin. can be creates b$ the same command ln b"t with o#tion Ds
P/am#le <% –s Lus*L/&;(-L+</ Lus*L/&;(-L%e?
 <% command difers from the "p3co#$5 command in that "p creates a
d"#licated co#$ of a 'le to another 'le with a diferent #athname, whereas <%
command creates a new director$ to reference a 'le(
 Oet-s %is"ali)e the content of a director$ 'le after the e/ec"tion of
command <%(
C-se 1# for hardlin. 'le <% Lus*L/&;(-L-" Lus*L*-!L'(@
The content of the director$ 'les 2"sr2di%$a and 2"sr2raj are
If c# command was "sed then the data contents will be identical and the K
'les will be se#arate objects in the 'le s$stem, whereas in ln Ds the data will
contain onl$ the #ath name(
L&)&t-t&+%s +2 :-*/ <&%M#
J( Aser cannot create hard lin.s for directories, "nless he has s"#er1"ser
K( Aser cannot create hard lin. on a 'le s$stem that references 'les on a
diferent 'le s$stem, beca"se inode n"mber is "ni&"e to a 'le s$stem(
Fiferences between hard lin. and s$mbolic lin. are listed below
The major diference between the stream #ointer and the 'le descri#tors are
as follows
The following lists some C librar$ f"nctions and the "nderl$ing ANIE A*Is that
are "sed to #erform %ario"s 'le f"nctions

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.