TOTO
child read Parent write
0
“T”
1
Fd1
parent read child write
0
1
Fd2
Step 1, parent writes to fd1[1]
Step 2, child read from fd1[0]
Step 3, child writes to fd2[1]
Step 4, parents read from fd2[0]
Parent process
write(fd1[1], &turn, 1);
read(fd2[0], &turn, 1);
write(fd3[1], &turn, 1);
read(fd4[0], &turn, 1);
Parent process
write(fd1[1], &turn, 1);
read(fd2[0], &turn, 1);
write(fd3[1], &turn, 1);
read(fd4[0], &turn, 1);
Write 1 read 0 write 1 read 0
fd1 “T” fd2 “T” fd3 fd4 T
“T”
Child process 2 TITI
player (s, f1, f2)
(f1==f3 and f2==f4)
read(fd1[0], &turn, 1);
…
write(fd2[1], &turn, 1)
Child process 2 TITI
player (s, f1, f2)
(f1==f3 and f2==f4)
read(fd1[0], &turn, 1);
…
write(fd2[1], &turn, 1)
Child process 1 TOTO
player (s, f1, f2)
read(fd1[0], &turn, 1);
…
write(fd2[1], &turn, 1)
Child process 1 TOTO
player (s, f1, f2)
read(fd1[0], &turn, 1);
…
write(fd2[1], &turn, 1)