Question 4
You procrastinated when assembling a team for your CS402 design project, and got
stuck with Kim, Khloe and Kourtney designing a data processing application.
You were surprised with
how proactive they were, because they finished their components within a couple
of weeks. But then, you realized that they were leaving the country
to record their new reality show, "The Kardashians Yodel in Switzerland,"
and they stuck you with the task of putting their pieces together. Here's what happened:
- Kim wrote a program called kim, which reads from standard
input and writes on standard output. It does the initial processing of the
data.
- Khloe wrote a program called khloe that processes the output of Kim's program.
It reads that on standard input, and writes on standard output. It works well for a
while, but Khloe got bored and had her program exit before it was finished reading the
input.
- Kourtney wrote a program called kourtney that starts reading from where
Khloe's program stops, and produces the rest of the output. Thank you, Kourtney.
Since they are paranoid about intellectual property theft, they've taken the source
code to Switzerland with them -- all you have are the executables.
All in all, that's not bad, but your application is supposed to serve a connection
on port 90210, connect to one client, read the input, process it and write the output
on the client connection.
Fortunately, you took CS360, so you can make this work. Here's what you are going to
do. You're going to write a program cs402 which does the following.
It's going to serve a socket and wait for a connection. Then it's going to launch
kim and make kim's standard input come from the socket.
It's also going to set up a pipe so that kim's standard output can go to
a khloe process' standard input. Obviously, khloe's standard output
will go to the socket.
Now, you're not going to close your file descriptor to the read end of the pipe or
the socket connection, because
when khloe exits, you're going to launch a kourtney process and have it
take over for khloe -- it will read from the pipe and write to the socket.
Write this program. I feel like I'm being too nice here, but I'd like for you to get
this right. Here's how you should set it up after you get the connection:
Your program should exit when everyone is done.