Previous Midterm Exam Questions Flashcards
Define the following terms and state how (or if) each pair of terms relate
to one another:
a) race condition and critical section
b) interrupt and context switch
A race condition is a event where the outcome of two concurrently running processes
depends on the order in which their operations are interleaved, sometimes
leading to incorrect outcomes.
A critical section is code that accesses some shared resource and that needs to be
run as if indivisibly to not allow another process to access the resource.
The code inside a critical section, if not protected, leads to race conditions.
Is it possible for different heavyweight processes to install their own interrupt
handler for the same interrupt? If yes, explain why each HWP does not invoke the
other HWP’s interrupt handler. If no, explain why the operating system prevents the
installation of different interrupt handlers.
Heavyweight processes can install their own interrupt handlers for the same interrupt.
The interrupt vector is part of the process’ state, so each process’ handlers are made
active when a context switch puts the process into the running state. Since the context
switch replaces the other process’ interrupt vector, you don’t invoke any interrupt
handler other than your own.
Suppose that the operating system wishes to implement two new system calls:
SUSPEND and RESUME. The SUSPEND call can be used by one process to suspend
the execution of another process. The suspended process remains suspended until it is
RESUMED by the process that originally suspended it. While a process is suspended,
it cannot run. Add transitions and/or states to the five-state transition diagram for
process states to account for the SUSPENDED and RESUME system calls. Label any
new transitions to indicate what causes the transition to occur. Label any new states
that you add, and briefly describe their purpose.
5 state model with 2 extra states:
1) Suspend blocked for suspending a process that is blocked
2) Suspend ready, for suspending a state that is ready.
a process can also be moved from 1) to 2) if it has finished its I/O before it was moved into the 1) state
Why is a context switch for a heavyweight process slower than the context switch
for a thread?
A heavyweight process has more overall state than a thread. In a thread’s context
switch, we just need to swap the program counter, register values, stack pointer,
and status register. In a heavyweight process context switch, we must also swap
the memory being used, interrupt vector and mask, open file table, and other
such resources as well as clear the cache. It takes time to make all these changes.
Even though context switches for heavyweight processes are slower, they still form
the basis of most operating systems. Why do we tolerate the extra time cost?
Heavyweight processes don’t interfere with one another. They are very safe that
way. If one crashes, the other processes can continue. We still base ourselves on
the heavyweight processes for the security and independence that they provide.
In a microkernel architecture, could interprocess communication between
processes be done outside the microkernel? Explain, considering both heavyweight processes
and threads.
IPC can be done outside the microkernel for threads. The threads share memory space
so they can do IPC using that shared resource. The microkernel doesn’t need to be
involved in the shared memory access.
For heavyweight processes, nothing is shared. So, the only way to pass a message
between heavyweight processes is through the microkernel.
Consider an implementation of interprocess communication between threads.
When given a message to send from one thread to another, the implementation can either
provide a pointer to the original message to the destination thread or can copy the
message to a new location and send a pointer to this copy to the destination thread.
Discuss pros and cons of the one of the alternative implementations.
At its core, this question is about pass-by-value versus pass-by-reference.
If we send a pointer to the original message then we have the least amount of data to
transfer to the other thread for the message to arrive. However, the sending thread
needs to not change the message or release the memory that contains the message until
it is sure that the receiving thread has read the message. It’s fast but isn’t as safe.
If we make a copy of the message then the sending thread and the receiving thread are
more isolated from one another, which is safer. However, it takes more time to make
the copy and we end up with two copies of the message, which can be a problem if the
message is huge and we have limited memory space.