(1) show initial shell (sh0.c) gcc sh0.c -o sh0 ./sh0 $ /bin/ls (2) cp sh0.c sh1.c modify sh1.c, inserting before the execv(): close(1); creat("tmp1", 0666); gcc sh1.c -o sh1 ./sh1 $ /bin/ls $ ^D cat tmp1 (3) create file ./script: /bin/echo one /bin/echo two ./sh0 < script ./sh0 < script > tmp1 cat tmp1 (4) ./sh1 $ /bin/ls sh0.c sh2.c shx.c $ ^D cat tmp1 modify sh1.c, inserting after creat(): close(2); creat("tmp1", 0666); gcc sh1.c -o sh1 ./sh1 $ /bin/ls sh0.c sh2.c shx.c $ ^D cat tmp1 modify sh1.c again, replacing the second creat() with dup(1) gcc sh1.c -o sh1 ./sh1 $ /bin/ls sh0.c sh2.c shx.c $ ^D cat tmp1 (5) ssh 32bit-linux-box linux% cd /proc/$$ linux% pwd linux% ls -l linux% cat maps linux% ls -l fd linux% exec 5>/tmp/out5 linux% ls -l fd linux% exec 1>/tmp/out1 linux% ls -l fd linux% exec 1>&0 linux% cat /tmp/out1 linux% exec 5>&- linux% ls -l fd linux% (6) cat file.txt sort < file.txt sort < file.txt | uniq sort < file.txt | uniq | wc -l (7) show pipe.c gcc pipe.c -o pipe ./pipe (8) add to pipe.c: pipe(fdarray) + int pid = fork(); + if (pid == 0) { write(fdarray[1], "hello", 5); + } else { n = read(fdarray[0], buf, sizeof(buf)); printf("%d bytes: %.*s\n", n, n, buf); + } gcc pipe.c -o pipe ./pipe (9) show sh2.c gcc sh2.c -o sh2 ./sh2 $ /bin/sort file.txt | /bin/uniq $