CS360 Final Exam - May 6, 2013 - James S. Plank - Page Three


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: 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:

and here's how it should look after Khloe exits:

Your program should exit when everyone is done.