Ospp Chap02 Part5
Ospp Chap02 Part5
Ospp Chap02 Part5
#include <stdio.h>
#include <unistd.h>
staticvoid charatatime(char *str){
char *ptr; int c;
setbuf(stdout, NULL);
for (ptr str; (c "*ptr++)
=
l=0;)
putc(c, stdout);
int main(){
pid_t pid;
if((pid fork()) <0)
printf("Fork Error\n");
else if (pid == 0)
charatatime("this is child\n");
else
charatatime("this is parent\n")
return 0;
The Output beu Ccan be: Cone possible).
Parest
ntiproce se LOauaicaGon
undamcotalmodels
Shared Mcmory-
Mess.aqePassinog
CShasLd memoxy Can be jastea as mecsaqe
passingis achieued typically usioq System Cals)
process A
kemel
pULa kaub heqade
process A
process BB
Mescagg
Pccainc
2wde L
message queue
mom,m2 ma mn
kernel
Shared lemery
EromeleiPuduce LonsumeL a b l e m
C producen proCeseprodules a aom
h a t 1S Consumcd 64 a Consomc process
Code
Acompile Iney produe Csscmbly
Consmed by Csscm6lc As semnblea
Locde
oduca &Consumua nf ca act tbrough shea
Cal it
shaand
ve
Bj/ C
he Sqnchr o n i a ton Oj prooduc ca &
G Consuma
Consumez
happens us a ly oia a implementaton
Crculac g u e u e
Llnbounded Buffc Uo practcal imit on the
Size o the buffe
bounded Bujje Fixed bujje Sihe
Mcss cePassng
Me csagu
Messag Sent Can be fxed leasy to implemcat
C vauable i'n Si 2e .
T O d to Comnuniate, cc communicatoo
n k mut exist between
processes. J6s Can be
achieved by
Pulonatic Cplieit
ujeng
Ppakash beq4
Waming
Lo dxect Commusicaton:
Send CP, mest
age)-
Sceive ( , messaqe)
T lodirect Commuotcation.
Sesd LA message)
seceive CA, cssaqe
Ais a maibo. cr psE
SunchonioGon
be
mcsSage pauing Con
-6locking
on-6locking
m e s s a 9 cs
Uon-Blockine
lock'ncq Casyne
Csiyn
Send Receive
Scod Receive
Buyfeain9
Zuo Copacby Queuelength is O. 7ust bave bloceirg
Send.
-Sochets
Remote ProCadure Cols
Piees
Remoke mehod Isvocaaon
ATE Queston
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute
concurrently.
P2
cE- D=2 B
B=D-
he number of distinct values that B can possibly take after the execution is_