0% found this document useful (0 votes)
14 views4 pages

Operating Systems Midterm Exam Guide

The document contains a midterm exam for an operating systems course with 14 multiple choice and short answer questions covering topics like process scheduling, interrupts, memory protection, and inter-process communication. It provides examples and explanations for the questions.

Uploaded by

viere1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Operating Systems Midterm Exam Guide

The document contains a midterm exam for an operating systems course with 14 multiple choice and short answer questions covering topics like process scheduling, interrupts, memory protection, and inter-process communication. It provides examples and explanations for the questions.

Uploaded by

viere1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Operating Systems 2023

U3680
National Taipei University

Midterm Exam [Chapter 1 - Chapter 5]

1. What are the goals of multi-programming and time-sharing? (6%)

• Multi-programming: increase CPU utilization and keep CPU busy (3%)


• Time-sharing: provide interactivity and reduce response time (3%)

2. Please answer the following questions about interrupts:

(a) What is the purpose of interrupts? (4%)


Interrupts provide an event-driven way to change the flow of control in the CPU.
(4%)
(b) List three types of software interrupts. (6%)
Invalid memory access, software error, system calls. (6%, 2% for each one)

3. Please answer the following questions about system protection:

(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

– Strength: naturally synchronized (1%), can communicate across machines


(1%)
– Weakness: slower (1%)
• Shared memory
– Strength: faster (1%)
– Weakness: need to handle synchronization (1%), cannot communicate across
machines (1%)

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%)

(a) Register values


(b) Heap memory
(c) Global variables
(d) Stack memory
• b and c are shared (4%)
• a and d could not be shared because different threads could run the different
parts (functions) of a program (4%)

8. Please answer the two advantages of thread pools. (6%)

• It is usually slightly faster to service a request with an existing thread than


create a new thread. (3%)
• It allows the number of threads in the applications to be bound to the size of
the pool. (3%)

9. Draw the diagram of the process state and briefly describe the meaning of each state. (10%)

• Diagram of process state (5%)

• – New: the process is being created (1%)


– Ready: the process is in the memory waiting to be assigned to a processor
(1%)
– Running: the process whose instructions are being executed by CPU (1%)
– Waiting: the process is waiting for events (e.g., I/O) to occur (1%)
– Terminated: the process has finished execution (1%)

10. What are the problems when the time quantum of the Round Robin scheduling becomes too
short and too long? (6%)

Operating Systems 2023 Midterm Exam


Operating Systems 2023 Midterm Exam 3

• 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.

Process Priority Burst Arrival


P1 1 10 0
P2 2 15 0
P3 3 15 10
P4 3 20 15
P5 4 10 35

(a) Show the scheduling order of the processes using a Gantt chart. (5%)

(b) What is the waiting time for each process? (5%)


• P1 : 60 (1%)
• P2 : 45 (1%)
• P3 : 10 (1%)
• P4 : 20 (1%)
• P5 : 0 (1%)

14. Using the program shown below, what are the outputs of this program? (8%)

Operating Systems 2023 Midterm Exam


Operating Systems 2023 Midterm Exam 4

{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))

Operating Systems 2023 Midterm Exam

Common questions

Powered by AI

Thread pools offer the benefit of faster request servicing because they use existing threads rather than creating new ones. They also limit the number of concurrent threads in an application by bounding it to the pool size, which helps in managing system resources efficiently and preventing over-subscription of CPU resources .

If the time quantum in Round Robin scheduling is too short, the system experiences high overhead due to frequent context switches. If the time quantum is too long, it effectively turns into a First-Come-First-Serve (FCFS) scheduling, causing long wait times for shorter processes if a long-running process executes first. This conundrum highlights the importance of choosing an optimal time quantum for a balanced approach .

SJF scheduling is difficult to implement because it requires knowledge of future CPU burst durations, which is inherently unknowable until processes are executed. In practice, approximations are made using predictions based on historical data, employing techniques like exponential averaging to estimate the length of future bursts based on observed past bursts, thus allowing the scheduler to make more informed decisions .

Operating systems protect CPU resources by implementing timers and using time-sharing. When a timer reaches zero, an interrupt is generated, causing a context switch to prevent any single process from monopolizing the CPU. Memory protection is ensured through the use of base and limit registers, which restrict the memory addresses a process can access, thus preventing one process from accessing the memory space of another .

In a multi-threaded process, heap memory and global variables are shared across threads. Register values and stack memory are not shared because different threads can execute different parts of a program; each thread thus requires its own execution state and stack space to manage its local variables and function calls .

The goals of multi-programming are to increase CPU utilization and keep the CPU busy by efficiently managing multiple programs. Time-sharing aims to provide interactivity and reduce response times by allowing multiple users to interact with a computer at the same time. While multi-programming is geared towards maximizing resource use and keeping the CPU fed with tasks, time-sharing focuses on ensuring that user interactions are timely and responsive, effectively sharing the CPU's time between different interactive tasks .

An API enhances portability by providing a consistent programming interface across different operating systems, regardless of the underlying implementation or hardware. This consistency allows programs to be recompiled rather than rewritten when run on different systems, minimizing the effort required to adapt software across platforms .

In preemptive scheduling, the operating system can interrupt and replace a running process based on priority or time slicing, allowing greater control over resource allocation. Non-preemptive scheduling allows a process to continue running once it has the CPU until it voluntarily yields or is blocked, which can lead to inefficient resource use if a low-priority, long-running process occupies the CPU. The choice between these approaches often depends on the desired balance between system utilization and response time .

The micro-kernel approach is safer as it minimizes the kernel's size, which can reduce bugs. Most components run in user space, so their crashes don't affect the entire system. However, it suffers from poor performance due to slow message-passing communication between components, as opposed to the faster function calls within a monolithic kernel .

Message passing is naturally synchronized and allows communication across machines but is slower due to the overhead of passing messages. Shared memory offers speed advantages since processes can directly read and write to memory, but it requires careful synchronization mechanisms to prevent concurrent access issues and does not support communication across different machines .

You might also like