Exam 1, Solution

Question 1: Resources Management (30 points)

There are trade-offs involved in adding a web browser to a general-purpose OS, as opposed to having the web browser as application software. Some of these trade-offs are technical, some are financial, some are legal, etc. This question concerns only the technical trade-offs.

A. List and explain one technical advantage to adding a web browser to the OS.

(As discussed in class, there are several technical advantages to building special-purpose functionality into an OS. You only need to discuss one for full credit. A reasonable example is increased speed.)

If the OS is properly designed and implemented as a resource manager, application software will only have access to resources, including communications resources such as network cards and modems, through system calls. Systems calls abstract the functionality of the hardware resources to make them uniform for all applications. The downside to this is that the translation from the system call interface to the actual hardware activities takes time. This time could be saved, and the application could run faster, if the hardware could be accessed directly using its native instructions.

B. List and explain one technical disadvantage to adding a web browser to the OS.

(Again, as discussed in class, there are several technical disadvantages to building special-purpose functionality into an OS. You only need to discuss one for full credit. A reasonable example is reduced security.)

If the OS is properly designed and implemented as a resource manager, application software will only have access to resources through the OS. Because of this, the only resources at risk due to a faulty application will be those resources allocated to that application. For example, with a faulty application web browser, files belonging to the user using the browser could be lost if it behaved improperly; however, system files and those of other users would definitely be protected. This minimizes the risk in the system.

On the other hand, if the browser software is integrated into the OS, any failure of the web browser could cause much greater damage to the system. In general, adding code to the OS makes it more likely that bugs have been added as well, increasing risk in the system. Therefor adding a web browser to a general purpose OS has the technical disadvantage of reducing security in the system.

C. For the advantage and disadvantage you listed above, which (if either) do you think is the more important? That is, do you think (1) the advantage you listed outweighs the disadvantage you listed, (2) the disadvantage you listed outweighs the advantage you listed, or (3) the advantage and disadvantage are of about equal weight.

(Your answer needs to make sense for the advantage and disadvantage you list.)

For the advantage of increased speed and the disadvantage of reduced security, the disadvantage clearly outweighs the advantage for a web browser. While speed can be increased slightly, the increase will be relatively small. Most of the delay in web browsing comes from the network and communication hardware, not from the processing within the browsing computer. On the other hand, security is a major issue on the web. The web should be considered a hostile environment - there are large numbers of people trying to cause havoc with computers by using the web. A few fractions of a second saved here or there over many months of web browsing cannot make up for the increased risk of losing or corrupting valuable data or even simply having one's computer offline for a short while as programs and data are restored after a problem. The expected costs clearly outweigh the expected benefits.


Question 2: Threads and Resource Management (30 points)

Una-May writes a process that has four threads. The first thread is the boss thread. It gets the name of the input and output files from the user and tells the other three threads to do the work. The other three threads are, then, the workers. One worker thread gets input from the specified input file, another does computation, and the last sends output to the specified output file. The file names are given to the input and output threads using global variables. The data is shared between the worker threads by using the heap-all three threads have pointers into the heap to access the data.

Unfortunately for Una-May, she uses an input function that allows for buffer overflows in the boss thread. In which of the following locations could data be corrupted based on this buffer overflow? (Assume the threads are implemented as kernel-level threads.) Explain you answers.

A. The static and global variables for the process.

The static and global variables for the process could be corrupted. It is very possible that global variables are being used directly by the boss thread as the input buffers for the faulty input function being used by Una-May. Even if she uses local variables within the boss thread for the buffers, the description above makes it clear that she uses global variables to pass information from the boss thread (where the buffer overflow may occur) to the worker threads. Doing so can corrupt the static and global variable space.

B. The heap.

The heap cannot be directly corrupted by this buffer overflow. Even a very large overflow in another part of memory shouldn't be able to get here if the OS is properly doing its job as a resource manager. However, it is possible for the data in the heap to be corrupted. If the input worker stack becomes corrupted (see below), then data being passed using the heap could likewise become corrupted, since it is being copied from the input worker thread's corrupted stack.

C. The stack for the boss thread.

The stack for the boss thread could be corrupted, based on what we know from the description above. The description is unclear as to whether the input buffers being used are global or local variables. However, if they are local, then the stack for the boss thread is where the data corruption will start.

D. The stack for the input worker thread.

The stack for the input worker thread could be corrupted, although not directly, since an overflow in a global variable or one in the boss thread stack should not overwrite data in the input worker thread's stack. However, it is quite possible, given the description above, that the input worker thread copies the input file name into a local variable. The value for this variable is passed to it through a global variable that could have an oversized data item loaded into it, because of the input routine that allows for buffer overflows. If this oversized data item is copied into the stack for the input worker thread, this stack could likewise become corrupted.

E. The stack for the computation worker thread.

The stack for the computation worker thread could not become directly corrupted, for the same reason that the heap and the stack for the input worker thread could not. However, because the computation worker thread could be copying data from the heap for local use and we have already determined that the heap could become corrupted, the stack for the computation worker thread could likewise be corrupted due to copying oversized data items here.

F. The stack for the output worker thread.

The stack for the output worker thread could not become directly corrupted, for the same reason that the heap and the stacks for the other worker threads could not. However, as with the computation worker thread, because the output worker thread could be copying data from the heap for local use and we have already determined that the heap could become corrupted, the stack for the output worker thread could likewise be corrupted due to copying oversized data items here. Also, similar to the problem described for the stack for the input worker thread, the stack for the output worker thread could become corrupted by copying the output file into a local variable. The value for this variable is passed to it through a global variable that could have an oversized data item loaded into it, because of the input routine that allows for buffer overflows. If this oversized data item is copied into the stack for the output worker thread, this stack could likewise become corrupted. (Only one method of output worker thread corruption need be given for full credit.)


Question 3: Scheduling (20 points)

Kalyanmoy notices that it takes half an hour for his (large) company to run the weekly payroll program-10 minutes for input, followed by 10 minutes of processing, followed by 10 minutes of output. He has heard of multiprocessing and thinks that by breaking up the payroll input file into multiple files and running a copy of the payroll program on each of the smaller files, they will be able to significantly reduce the time it takes to complete the entire payroll. He brings this idea to his boss who says, "Silly Kalyanmoy, the computer running the payroll is a batch system-there is no preemption in the scheduler, so multiprocessing won't help."

A. Who is right? That is, is multiprocessing likely to significantly reduce the time it takes to complete the entire payroll? (Assume that all the data needed to process a single employee is stored in that employee's record and it would be feasible to break the file up into smaller files between employee records.) Explain your answers.

Kalyanmoy was right. Multiprocessing can reduce the time it takes to complete the entire payroll. The reason is that when a payroll program does something related to I/O, it doesn't need the CPU and other copies of it can use the CPU to process the data that were read from input devices. (Note that while the system does not preempt processing that are running, if a process requests I/O, it is volunteering to leave the running state for the waiting state, so another process may be scheduled to run on the CPU.)

B. If you said that multiprocessing on a batch system won't significantly reduce the time it takes to complete the entire payroll, would it slow down the processing? If you said that multiprocessing on a batch system will significantly reduce the time it takes to complete the entire payroll, by how much would it reduce the time in the best case scenario, if the payroll file were divided into 10 equally-sized smaller files? Explain your answers.

In the best case scenario, there are no processes on the computer other than our 10 processes and the input and output devices are different so that we can do the input and output at the same time. The following figure will draw the scheduling for those 10 processes. The time reduction is 30/12 = 2.5

multiprocessing diagram


Question 4: Process states, fork, exec, and wait (20 points)

For all parts of this question, interpret "it succeeds" as meaning that there were no errors.

For the primary answers given, please consult the following diagram.

state diagram

A. When a process does a fork system call and it succeeds, should it stay in the running state or be moved to another state? (If another state, which one?) Explain your answer.

There is no reason that the parent process cannot stay in the running state, since it is already there and it will continue running with the statement immediately following the fork system call. So, in the general case, it will should stay there.

However, there is a particular special case to consider. It is possible that the parent has used its entire time quantum by the time fork has completed (in fact, it is rather likely as fork is an expensive system call), in which case it should be moved to the ready state.

(Note that, for this particular case, you may choose to use one of the state diagrams from the book. If you use the one on page 222, then the parent process should be placed in the sleeping state. If you use the one on page 227, then the parent process should be placed in the readyActive state.)

B. When a process does a fork system call and it succeeds, should the newly created process be placed in the running state or another state? (If another state, which one?) Explain your answer.

Using the process state diagram we have used in class and that is reproduced above, all newly created processes will start in the "new" state. (Note that you may choose to use one of the state diagrams from the book. If you use the one on page 222, then the new process should be placed in the runnable state. If you use the one on page 227, then the new process should be placed in the readySuspended state. I.e., it will always be the state pointed to by the Start arrow.)

C. When a process does an exec system call and it succeeds, should it stay in the running state or be moved to another state? (If another state, which one?) Explain your answer.

As with part A, there is no reason for the process not to continue in the running state in the general case. Note that there is no new process created with exec. Instead, the process is still there but the program in that process was changed.

However, the particular special case is similar to that of part A.

D. When a process does a wait system call and it succeeds, should it stay in the running state or be moved to another state? (If another state, which one?) Explain your answer.

There are two cases to consider.

  1. The process has at least one zombie child process (a child that has terminated but not yet been waited for by its parent).
  2. The process has no zombie child processes.

(For grading, you do not need to use the term "zombie" as long as you accurately describe these cases.)

(There are two alternate explanations for each case. I'd accept either.)

(1) The process should stay in the running state because the purpose of calling wait may have been to let the child complete its activities before the parent proceeds. Since the child has exited, its activities are complete, so the parent may proceed.

(1) The process should stay in the running state because the purpose of calling wait may have been to get the child's exit information. Since the child has exited, this information is immediately available so the wait system call can return this information immediately.

(2) The process should move to the waiting state because the purpose of calling wait may have been to let the child complete its activities before the parent proceeds. Since the child has not yet exited, its activities are not yet complete, so the parent should wait.

(2) The process should move to the waiting state because the purpose of calling wait may have been to get the child's exit information. Since the child has not yet exited, this information is not immediately available so the wait system call cannot return this information immediately.

(Note that you may choose to use one of the state diagrams from the book. If you use the one on page 222, then the state for case (2) is sleeping. If you use the one on page 227, then the state for case (2) is blockedActive.)