Ospp Chap02 Part3
Ospp Chap02 Part3
printed
nclude <s tdio. b
Finclude <unistd.b
maioO
foxh
foxk
fork
PAiat C'bello In')
atusa 0,-
P Pa
Lotol -8
sses whes o iS
UD rbes Poce
Lhe hum beu o forCcalls
3 - 2
the
What wiu be the outputb o the
ollocing
ollocinG
PAogam
Coid PC ()
if fork O ==0
PAintf C"Childl»')
else
Paint+C"Pasnt »")
int m a i n ) i
PC C
Utwo 0
The
e Output Canbe :
ChiLd
Pant
OR
Pasnt
Chilo
The
The tota L Dumbe o1 chiled proce ses
Cxeated is:
an
6a-|L
da?-
Apsw b-
Write a program to acbieve h e qollDwing:
& t e a nate
Eor a passnt Create 3 childres
O4 llouws
Fixst,thizd Child taminates
tinclude <onisto.bS
int mafn )
sleepl3)
pinttC" childl id /.d Parent id Zd Int
getpidl, getppid)
clse
pid2 forkl)
if Lpidz #o
Sleepla)
prinlt C child2 d =7.d, Amnt id 1dln,
getpd , gebppidC)
else
pid3-forkt),
fpid 3 o )
puntfC" chilA3 /d
/d Pareot a
getptdc,gebppid):
psakasb beaade
else
SleepC+);
pouinLfC Pamnt id , d l n " , getpidl));
tua 0
Sample Output
t ma?nl)
pld-t pid;
pid- foak C)
it Cpidzo)i
fpointf Cstder "Fosk Failed"y
Jutun ;
3
List teu
else if Cpid ==o)£ nivLL)
C"/bio l s ",_ "Ls", by UL
Czeclp Command
ind Command
Lwboe to
else
Wart NULL),
parent (pkd> 0)
wait() parent resumes
parend pid tork
h i d (pid = 0) exec) exil)
Amnten
Apasnt ray tuminate h e executon o One
ts children JOrC variety o deasons Sucb as,
The
The child has cXcee ded it ss s age Some
the e soub Ces Lhct rt ha been alocated
T7e Ls acu
iqncd to ch'ld 1S oo
longe-
ncui'red
ExitCD
t o tuminate
Pa
Pasnobmay tesminate the executon o1 children
Processes ucig the