And now, there is some cooking advice
The explanation in this lab is simple. Implement the system calls
dup(), dup2() and pipe(), and make sure that
close() works correctly with these. When you're done you should
be able to use jsh and connect processes with pipes.
As before, the outcome of the previous KOS labs (lab4 and lab5) contribute
substantially to the success of this one. In "real life" it would probably
go this way as well. First, you'd get the I/O subsystem working, then you'd
get some rudimentary process management happening, and then you'd start with
the good stuff. As such, if you find yourself fixing bugs in your lab4 or
lab5 code while you work on lab6, you are having the true operating systems
experience.
Compilation and Linking
In the kos_pipe directory you will find a Makefile
that will link your code with the version of
simulator.h that you will use for this lab along with:
- /cs/class/cs170/lib/libsim.a
- /cs/class/cs170/lib/libkt.a
- /cs/class/cs170/lib/libfdr.a
- /cs/class/cs170/lib/main_lab2.o
Subtleties
You'll have to deal with certain events correctly. For example,
if you write to a pipe that has no read end, your process should
die quietly (i.e. we're not going to deal with catching SIGPIPE
signals). If you are blocked writing to a pipe and the read end
goes away, your process should die quietly. If you are blocked
reading from a pipe and the write end goes away, the read()
system call should return zero. If you have written bytes to a
pipe, but they never get read, that's ok -- make sure it isn't a problem
(i.e. a memory leak). We would also like the semantics of pipe reading/writing to be like Unix.
For example, if one process does write(p[1], buf, 10) and
the process on the other side of the pipe does read(p[0], buf, 20),
the read() call will return with 10 bytes.
Test executables can be found at
/cs/class/cs170/test_execs/.
Of particular interest should be the code pipe_test.c and the binary
you can find in /cs/class/cs170/test_execs/jsh. The binary jsh
should run in your simulator as long as you do not attempt to redirect the
shell input or output (you have no file system). You should use jsh to
test out different combinations of the programs in
/cs/class/cs170/test_execs communicating via pipes.