CS360 Midterm -- May 2, 2002


Question 3

Your job is to write the program launcher. Launcher takes an arbitrary number of arguments, greater than zero:

UNIX> launcher program arg1 arg2 arg3 ....

Now, what launcher does is the following. It creates a new process that executes the program program with the given arguments. The only thing special about this is that standard error for this program should go to a server process that is serving a socket on host cetus3a.cs.utk.edu, port 13700. Launcher should not return until program is finished.

Assume that program is an absolute or relative pathname of a file -- you should not search your PATH environment to execute it.

Question 4

Suppose there are three sensors, each serving a socket on port 9200 of the machines cetus4b.cs.utk.edu, o.cs.uscb.edu, and liz.cs.harvard.edu. These sensors accept an arbitrary number of connections, and to each connection, they periodically write a 20 character text string. The last character is a newline.

Your job is to write a program psens, that connects to all three sensors. Whenever a sensor writes its text string, psens prints that string to standard output, prepended by the overall line number, and host name that wrote the string.

Here is example output:

UNIX> psens
    1 o.cs.uscb.edu      1020352943 XUSOWJNEI 
    2 cetus4b.cs.utk.edu 1020352948 SPWJNEJSX 
    3 cetus4b.cs.utk.edu 1020352955 9 2j SJWW 
    4 liz.cs.harvard.edu 1020352955 JJJSSS99! 
    5 o.cs.uscb.edu      1020352980 -- -- XXX 
    6 liz.cs.harvard.edu 1020352978 ++@(*# JJ 
...
You may use threads for this program, but you do not have to. You must use the system call read() to read from the sensors.

Your program should not garble the lines (e.g. write half of one, then half of another).

If any connections close, the program should exit.