1) Time-sharing refers to sharing a computing resource among many users(interactive users). In the early days this was done because early computers were expensive and often time the computer would spend time idly waiting. Multi-Programming is when multiple processes run that share the same cpu. Only one process is actually serviced by the cpu at a time but it appears to the user as if they are all running simultaneously.
2) Kernel mode(supervisor mode) will have the mode bit set so that it is in supervisor mode. In supervisor mode the processor can execute every instruction available to it in hardware. When the bit is set to user mode it will only be able to execute a subset of the instructions. It must request the OS to perform a restricted function on it's behalf.
3)
1. Trap. The user process can execute a trap instruction(e.g. system call). A trap is known as a synchronous software interrupt. Trap points to an instruction in the kernel.
2. Exception. The user process can cause an exception(divide by zero, access bad address, bad instruction, page fault. etc.)
3. Interrupt. The processor can transition into kernel mode when receiving an interrupt.
4. I = System call. System calls enter the kernel by sending a message, letting the kernel do some kernel work, then returning.
4) A thread is a lightweight process. It contains only the minimal elements it needs to run. A process is an instance of a computer program that is being sequentially executed. A process and a thread are each created with a system call. Modern OS system call to create a process also usually creates a base thread to execute the process. In Windows CreateProcess() system call first creates a modern process and then it creates a base thread for the process.
5) Need to save the registers, stack pointer, and program counter into the thread control block (TCB) of the thread that that is no longer running. Need to reload the registers, stack pointer, and program counter from the TCB of the new thread.
When the threads are from different processes, need to not only save and restore what was given above, but also need to load the pointer for the top-level page table of the new address space. (Note that this top-level page table pointer from the old process does not need to be saved since it does not change and is already contained in the process control block (PCB)).
6)
1. The user can execute a yield() system call.
2. The user code can request an I/O operation.
3. The user code can request a wait() operation for another thread (such as thread-join)
7)
1. Shared memory. This requires translation hardware (segments or tables) in order to map a shared piece of DRAM into two different address spaces.
2. Message Passing. Doesn't require hardware support.
3. Through the file system. Doesn't require hardware support (other than the support that was already there for the file system).
8) An interrupt is an external signal. When interrupt occurs and is enabled (which means that it is not masked off and the primary interrupt bit in the processor is turned on), then the processor will stop the current running code, save the PC, disable interrupts, and jump to an appropriate handler. The function of the interrupt controller is to provide some control over which hardware interrupt signals are enabled and what their priority is.
9) A race condition is when the outcome of the process is critically dependent on the sequence or timing that the processes execute their respective critical sections. The problem occurs because of sharing not because of any problem in sequential code. Example: Process 1 loads a variable "balance".Then an interrupt occurs and Process 2 takes over. It performs an operation on the balance. This is before the first process finished doing what it was doing so this is a problem.
10) A critical region of a program is a section in which it is imparative that only one piece of code accesses a resource at a time. An example is a variable that holds a number. It is important that once a process starts using it no other process uses it. This relates to synchronization because critical region problems can be solved with synchronization.
11) A small time quantum: Argument against: Bad for efficiency. A small time quantum requires the timer to generate interrupts with short intervals. Each interrupt causes a context switch, so overhead increases with a larger number of interrupts.
Argument for: Response time improved. A short time quantum will allow short jobs to finish quicker and produce results to the end user faster than with a longer time quantum.
12) First-come, first served: (FCFS)
10,22,20,2,40,6,38
= 10 +12+2+18+38+34+32 = 146 cylinders
146 x 6 milliseconds = 876 milliseconds
Shortest Seek Time First: (SSTF)
20,22,10,6,2,39,40
= 0+2+12+4+4+36+2 60 cylinders
60 x 6 milliseconds = 360 milliseconds
LOOK(initiated moving upwards)
20, 22,38,40,10,6,2
=0+2+16+2+30+4+4 58 cylinders
58 x 6 milliseconds = 348 milliseconds
13)
The clock interrupt handler is run 75 times every second, which takes 75 x 2 = 150 ms. This is 1 5% of the CPU time.
14) see print outs
15) see print outs