0% found this document useful (0 votes)
8 views7 pages

Ospp Chap02 Part3

Uploaded by

venomzeus79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Ospp Chap02 Part3

Uploaded by

venomzeus79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Count the Umbu o time, "hello" 1S

printed
nclude <s tdio. b
Finclude <unistd.b

maioO

foxh
foxk
fork
PAiat C'bello In')
atusa 0,-

i a kO; foxk - fork),


P Parenb
childzeo
P Pr CxLatecd

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

Fnclude <s tdo. bb>


# ioclude cunistd. b>

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

Both process cA u n i n 9 Concuxrently ý


we dont k n o wbethu S wilL q ive Control
to paunt pro ces o child pxocess.
Pakash heqacde
ATE Cues ton

A process Cxecut es the ollowinq code:

fos Ciz o, ien; ir+)


forhl

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

Second, Second Child teamina tes


Jhird, FirstChild teumina tes
L a c 4, Parent team1nates

Child process (ds must ée


Pareo t E
at eveRypba se a n d I'n he end,
prin ted.
Pu'nt he pavent d .

The tamination Seg unca rovst be strictly


above,
.

include stoo.b >

tinclude <onisto.bS

int mafn )

int pidl, pd2, pid3,

P.ol fo» kl);


t Lpid l 2=0)

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

child3 d 133 Paxeat id = 3o


child 2 id 132 Paxentid -130
child id :31 Pareatid E130
Pareot id = 130

Baoe o4 exec Qnd u a i t


Systuatt.b-
#incluse éeys|t4peab>
incude Lstdio. b>
ttinclude <unistd.b)

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),

pint fC "hsld Comple t e );


wil Wait yos the
parant
Child to c o p l e t e
Sutiwn O,

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

Tye puvert S Citing, ind the OS docs


not
n ot allow a
chi Ld to Continue if its
paten
teiminates

Cas Cad ng teamioaton


- S o e Sys tems do not a uow a ch'Ld to
existiit parent bas temnated. Io Such Systums
1 a pxOCess taminates , then all o its childen

musE alko tuminate. Jhis


phenomenon IS
Kaj ed t as Cucading tamiDabon

ExitCD
t o tuminate

Pa
Pasnobmay tesminate the executon o1 children
Processes ucig the

abor EO-Sys tem cal

when the pxoce ss teaminatu,pOxmalle as


aboomaluy h e Rcanel nobijiesthe parent by
SendirG he S1CacHLD SIGnal to t h e parent.
Sendna
IUote a y s lo taminete

Retuun rom mafn . Colulng exit

exit o -Ex?t Retun q the last


CoUin9
shread yrom its S t a u t r o u tinee S. Calling
pthread - ex? tJvom the last Aread 6 Cau's
abor b Receipt o Signa . Response o
te Lout tbread to a CanceJaGon recuest.

You might also like