NAME:_____Answer Sheet__________________________
Answer all questions. (There are a total of 122 possible points.)
This is a closed-book exam. Use separate paper for your answers, as needed. If you have a problem understanding a question please either (1) raise your hand to ask me for clarification, or (2) write a note pointing out how you interpreted the question, and then answer the question according to your interpretation.
Budget your time accordingly! I strongly recommend that you read through the entire exam before starting.
TRUE/FALSE (2 points each; 20 total)
__T__ (AM) A rendezvous can be between any number of processes.
__T__ (PM) Signaling is always between exactly two processes.
__F__ (AM) The operating system switches processes by switching process Ids.
__F__ (PM) Processes all share the system stack when they are in user mode.
__F__ (AM) SOS always uses the disk interrupt handler when reading the disk drive.
__F__ (PM) The disk interrupt handler is always called when disk I/O is performed.
__T__ (AM) Messages are buffered in SOS so that they can be sent before received.
__F__ (PM) Messages in SOS are buffered so they can be received before being sent.
__F__ (AM) A shell converts all user input into system calls.
__F__ (PM) SOS uses the UNIX fork()/execv() method of process creation.
__T__ (AM) A process has at least one thread.
__T__ (PM) Threads permit asynchronous I/O within a process.
__T__ (AM) The Java Vector class implements an array of objects that grows in size as necessary.
__F__ (PM) JavaSOS permits the loading and execution of process binaries from disk.
__F__ (AM) Enabling disk interrupts in a SOS CreateProcess() system call is easier to handle than disabling disk interrupts.
__F__ (PM) The overhead of executing a system call is less than the overhead of a function call.
__T__ (AM) The Producer-Consumer IPC pattern is a variant of signaling.
__F__ (PM) A race condition is won by the first process performing the update on the shared resource.
__F__ (AM) Race conditions can be safely ignored.
__T__ (PM) A sequence of actions that must be done one at a time is called a critical section.
Short Answer (5 points each; 25 total)
3. (PM) Explain the relationship between pipes and standard input/standard output. A pipe is a natural structure for connecting the standard output of one program to the standard input of another. A shell, such as any UNIX shell, will automatically create a pipe based on the presence of a metacharacter (such as the "|" symbol) and connect the standard output of the first process to the standard input of the second.
4. (PM) Name three fields you would expect the stat() call to return. Any three of the following: file owner, file permissions, file creation date, file last modification date, file last access (read) date, file length.
5. (PM) On the CRA-1 how is the rti instruction used? The rti instruction (return from interrupt) is used to return control back to the point prior to an interrupt occurring. It is typically the last instruction in an interrupt handler.
Definitions (4 points each; 32 total) - Define the following terms.
1. (PM) ½ of a context switch – The steps necessary to either save the state of a process (the half of a context switch that occurs at each interrupt) or restore the state of another (possibly the same) process (the half of a context switch that occurs at the end of the Dispatcher()).
3. (AM) iva – the interrupt vector address register of the CRA-1, a control register that points to the location in memory where the interrupt vector table resides.
3. (PM) time quantum – value loaded into the CRA-1 timer register that controls the maximum amount of time that a process will be allowed to run in the run state before the timer interrupt causes a context switch. In other words, the maximum amount of CPU time that a process may use before being context switched (also known as a time slice).
4. (PM) "friendly" non-preemption – a form of non-preemptive CPU scheduling where a program is expected to occasionally "give up" the CPU. This is typically done in event-based windows programming, where a program will call a routine that will block waiting for the next window/mouse/keyboard event.
7. (AM) Critical Section - A sequence of actions that must be done one at a time.
Problem Solving (15 points each; 45 total)
1. Given the following JavaSOS definitions:
class SOSProcessDescriptor {
public boolean slotAllocated;
public int timeLeft;
public int state;
public int base_register;
public int limit_register;
}
(AM) Extend JavaSOS by adding a system call that returns the process ID to the calling process, modeled after the UNIX getpid() system call. Here is an example of how it would be used in, say, AppTests.java:
int myPID = MakeSystemCall((SOSSyscallIntHandler.GetPIDSystemCall, 0, 0);
SIM.Trace(SIM.TraceApp, "My Process ID = " + myPID);
Write the code for SOSSyscallIntHandler.java to add this new system call.
static final int GetPIDSystemCall = 9; // any value other than 1-8
.
. (anywhere within the switch statement of the HandleInterrupt() method):
.
case GetPIDSystemCall:
// Return the current processes PID
SIM.hw.SetCellUnmapped(addr + base_reg, cur_proc);
break;
NOTE: You will get near full credit for having the correct method name, even if you didn’t put down the full instance chain (in this case, SIM.hw). As long as you SetCellUnmapped() the value of cur_proc into cell 100 of the calling process.
(PM) Extend JavaSOS by adding a system call that returns the remaining CPU time left to the calling process. Here is an example of how it would be used in, say, AppTests.java:
int timeLeft = MakeSystemCall((SOSSyscallIntHandler.GetCPUTimeLeftSystemCall, 0, 0);
SIM.Trace(SIM.TraceApp, "I have " timeLeft + " milliseconds left in this time slice");
Write the code for SOSSyscallIntHandler.java to add this new system call.
static final int GetCPUTimeLeftSystemCall = 9; // any value other than 1-8
.
. (anywhere within the switch statement of the HandleInterrupt() method):
.
case GetCPUTimeLeftSystemCall:
// Return the current processes timeLeft
SIM.hw.SetCellUnmapped(addr + base_reg, SIM.sosData.pd[cur_proc].timeLeft);
break;
2. (AM) A SOS programmer attempted to write some code that is supposed to make two processes reach a common point in their code. Correct the problems in the code and state what type of IPC pattern this code is trying to achieve.
void main() { // process "A"
int queueA = AttachMessageQueue("/usr/queueb");
WaitForEmptyMsg(queueA);
int queueB = AttachMessageQueue("/user/queuea");
SendMsgTo(queueB);
}
void main() { // process "B"
int queueA = AttachMessageQueue("/usr/queueb");
WaitForEmptyMsg(queueA);
int queueB = AttachMessageQueue("/usr/queuea");
SendMsgTo(queueB);
}
This is the Two-process Rendezvous code found on page 243 of the book, with mistakes introduced:
2.(PM) A SOS programmer attempts to write code that manages a resource potentially useful to other processes. Correct the problems in the code and state what type of IPC pattern this code is trying to achieve.
void main() { // process "A"
int msg[6];
int q1 = AttachMessageQueue("q1");
int q2 = AttachMessageQueue("q2");
SendMsgTo(q1, 3.14, q1);
ReceiveMessage(q2, msg);
}
void main() { // process "B"
int q3 = AttachMessageQueue("q2");
int msg[8];
while (1) {
SendMsgTo(msg[1], msg[0]/180);
ReceiveMessage(q3, msg);
}
}
This is the client/server code on page 251, with the "squaring" server now turned into a "divide by 180" server. Various mistakes have been introduced:
Fill in the missing labels of the diagram above.
The diagram is the process state diagram taken from page 128 of the textbook.
(AM)
(PM)