112 Midterm
112 Midterm
U3680
National Taipei University
(a) How does an OS protect the CPU resource (for example, avoid an infinite loop of user
programs)? (3%)
Implement timers and use time-sharing. When the timer reaches the value 0,
an interrupt occurs for the context switch. (3%, answering one of timer or
time-sharing can get all scores)
(b) How does an OS protect the memory space of a process? (3%)
Use the base register and the limit register to restrict the memory address that
a process can access. (3%)
4. Describe why Application Programming Interface (API) can improve portability. (4%)
Different OSes share the same programming interface despite the underlying imple-
mentation or hardware being different. For this reason, when a program needs to be
run on a different OS, it just needs re-compiling, not re-writing. (4%)
5. Why a micro-kernel approach is usually safe (3%) but has poor performance (3%)
The micro-kernel approach keeps the Kernel as small as possible (fewer bugs). It is
also safer because most parts of the original kernels are moved to user space. Thereby,
a crash of these system programs will not lead to a crash of the entire system (3%).
However, the communication between components requires message passing, which
is slow. (3%)
6. Message passing and shared memory are two inter-process communication models. Please
list their advantages and disadvantages as many as possible. (6%)
• Message passing
Operating Systems 2023 Midterm Exam 2
7. Which of the following components of the program state are shared across threads in a
multi-threaded process? (4%) Describe why the rest parts could NOT be shared. (4%)
9. Draw the diagram of the process state and briefly describe the meaning of each state. (10%)
10. What are the problems when the time quantum of the Round Robin scheduling becomes too
short and too long? (6%)
• Too short: the context switch occurs too frequently, resulting in high overhead
(3%)
• Too long: RR will become an FCFS scheduling algorithm, if a long process comes
first, other processes would wait too long (3%)
11. What is the difference between preemptive and non-preemptive scheduling? (8%)
• Non-preemptive: the OS can not interrupt a process if it is under its CPU burst.
CPU scheduling can only be performed when a running process is terminated or
switched to the waiting state. (4%)
• Preemptive: the OS can interrupt a process even if it is under its CPU burst.
Besides a running process being terminated or switched to the waiting state,
scheduling can also be performed when a context switch happens or a process is
switching from the waiting state to the ready state. (4%)
12. Describe why the original shortest-job-first scheduling is difficult to apply in real-world cases.
(3%) How do we approximate it? (3%)
We will never know the duration of the CPU bursts of processes until they are
executed. (3%) We can only use the prediction of CPU bursts estimated from
previous CPU bursts. (3%)
13. The following processes are being scheduled using a preemptive, priority-based, round-robin
scheduling algorithm. Each process is assigned a numerical priority, with a higher number
indicating a higher relative priority. The scheduler will execute the highest priority process. For
processes with the same priority, a round-robin scheduler will be used with a time quantum of 10
units. If a process is preempted by a higher-priority process, the preempted process
is placed at the end of the queue.
(a) Show the scheduling order of the processes using a Gantt chart. (5%)
14. Using the program shown below, what are the outputs of this program? (8%)
{0, 3, 6, 9};
• line X: CHILD: 0 CHILD: -3 CHILD: -12 CHILD: -27 (4%, get 2% if the numbers
are correct)
• line Y: PARENT: 0 PARENT: 3 PARENT: 6 PARENT: 9 (4%, get 2% if the
numbers are correct))