Note that I will add problems to this list from time to time, but unless I warn you otherwise, only by adding entire new chapters at the end. So if you check back, tell your browser to reload the page (in case it has an old version cached) and then look and see if there are any new chapters after what used to be the last chapter with problems
forker.c
which is
linked to the web version of this homework contains a simple program
that loops three times, each time calling the fork
system
call described in section 4.3.1 of the textbook. Afterwards it
sleep
s (does nothing) for 30 seconds. Download this
file, compile it using the command
cc -o forker forker.cand then run it using the command
./forkerWhile the program is in its 30 second sleep, in a second terminal window do the command
ps xto get a listing of processes. How many processes are shown running the
./forker
command? Explain.
printf("Child Complete");has been removed. In variant2, both that line and also the preceding line
wait(NULL);have been removed. Each of these variant programs is compiled and run in a shell terminal window. What difference might be observed between variant1's behavior and variant2's behavior? Explain. You are welcome to try the experiment if you would like.
As background information, I'll summarize the scheduling algorithm used in both versions of NT. (This description is simplified, but gives the essential features.) The basic scheduling algorithm is a preemptive multilevel queue, with one queue for each priority level and round-robining among the processes at any one priority level. Under normal circumstances, all a user's processes will be at the same priority level (8, as it happens) and will use the same time quantum for round-robining (normally 30 milliseconds). Of course, a process may not run for its full time quantum - it can be preempted by an arriving higher-priority process, in which case it will get the remainder of its quantum when it resumes, or it can go into a waiting state before the quantum is up, in which case it gets a fresh quantum when it again becomes ready to run.
With this information as background, here is the difference between NT 3.x and 4.0: in 3.x, the foreground application gets boosted to a higher priority level, whereas in 4.0 it instead gets double the normal time quantum. (In 3.x it keeps the normal quantum and in 4.0 it keeps the normal priority.)
Explain what you would expect the user-visible results of this difference to be, and why. Specifically, answer each of the following questions, and explain your answers.
notifyAll
in Figure 7.36, page 214, can
be safely changed to notify
. Also, how can that code
be changed to do fewer notifyAll
or notify
operations?
dbReading
instance variable.
As further clarification, let us use the following names:
d = the distance covered while accelerating
t = the time spent accelerating
L = the seek distance
T = the time spent accelerating and decelerating
t' = the total time spent, including settling
The equation in part a is consistent with these names; the
d and t it talks about are those specified
above. In addition to this equation relating d and
t, you should be able to write two very simple equations,
one relating d to L, and one relating
t to T. Your goal in part a is to take those
three equations and do some algebra to get an equation of the form
T = y L1/2
where y is some constant that can be expressed in terms of
the constant a.
The equation in part b is not consistent with the
above names; what it calls t is really t'. The
given equation is then
t' = x + y
L1/2
which makes sense, because it is saying that the total time,
t' is a constant settling time, x, plus the
acceleration and deceleration time, T. Your job is now,
given two specific pairs of numerical values for t' and L,
to find out what numerical values x and y must have.
Versions of the Server.java, Connection.java, and Client.java files from Figures 15.2-15.4 are in the directory ~max/MC78/2001-Fall/src/chap15/sockets/. (These versions are the ones the authors have made available on their web site. They are not identical to the ones in the book, due to bug fixes.)
First, make sure you understand how to compile and run these programs by doing so. In particular, make sure you can use telnet to access the Server. (You can use the name "localhost" rather than 127.0.0.1, or can telnet using the actual hostname, even from another machine.) Next, modify the Connection.java file (and possibly also the Server.java file) so that the server no longer prints out the date and time, but instead does the following:
Your new server won't be usable with the java Client, just with telnet. Try your new server out. Run it, and then repeatedly telnet to it. (As before, you can do so from different machines, or on the same machine using localhost.) Make sure that each time it reports the line of input that was provided the previous time, except the "First time."
Instructor: Max Hailperin