COMP 3150Operating Systems

Unit 3 · Self-check

Unit 3 Self-Check Quiz

Twenty-five questions covering the process abstraction, the state model, the PCB, scheduling basics, and context switching. Each question can be expanded to reveal a model answer.

25 questions Self-paced Ungraded

Questions

Multiple choice and short answer

Answer each question before expanding. These span all five lessons of Unit 3.

Question 1

Which of the following is the best description of the difference between a program and a process?

Show answer
The second choice. A program is a file on disk containing machine instructions — a passive artefact. A process is that program in execution, with its own address space, program counter, registers, file descriptors, and resources. The same program can give rise to many processes at once; a single process can execute code from multiple programs over its lifetime (through exec).

Question 2

Which of the following is NOT a region of a typical process address space?

Show answer
Kernel segment. The kernel's code and data are not part of any process's address space — they live in kernel memory and are inaccessible to user code. The process address space has text, data, BSS, heap, and stack regions, plus command-line arguments and environment strings. (In some systems a small portion of the kernel is mapped into every process's address space to make system-call entry fast, but that is a kernel mapping, not part of the process's own memory.)

Question 3

Why do the heap and stack grow toward each other rather than away?

Show answer
So that the large unused space in the middle can serve either purpose. A program with heavy dynamic allocation but shallow recursion gets more heap; a program with deep recursion but little allocation gets more stack. By placing the two growing regions back-to-back and pointing them at each other, the kernel lets the workload decide where the boundary falls. The alternative — reserving fixed maximum sizes for each — would waste address space in every program.

Question 4

A process is in the Blocked state. Which of the following transitions is possible?

Show answer
The second choice. A blocked process can go to Ready when its awaited event occurs, and it can go to Terminated if it is killed while waiting. It cannot go directly to Running — the scheduler only selects from the Ready queue. It cannot return to New, which is a transient state that precedes Ready.

Question 5

Which of the following is the correct description of the Running → Ready transition?

Show answer
The transition occurs when the running process is preempted — the kernel takes the CPU away and returns the process to the ready queue. It is triggered by a timer interrupt or by a higher-priority process becoming ready. It is the only transition that requires hardware support (a timer), and it is involuntary from the process's point of view. Without this transition, a process that never blocks would monopolise the CPU indefinitely.

Question 6

Which of the following is the correct interpretation of the S state code in the STAT column of ps?

Show answer
The first choice. S means the process is blocked on an event (typically I/O or a timer) and can be woken by a signal. The stopped state is T; a zombie is Z; a process in uninterruptible sleep is D.

Question 7

Which of the four PCB groups contains the saved program counter and general-purpose registers?

Show answer
Saved processor state. This group holds everything about the CPU's registers at the moment the process was suspended: program counter, stack pointer, frame pointer, general-purpose registers, status flags, and (usually) the floating-point state. It is the group that is rewritten on every context switch.

Question 8

What is the difference between a process's real UID and effective UID, and why does the kernel track both?

Show answer
The real UID identifies the user who started the process. The effective UID is the identity used for permission checks on file access. They differ when a program has the setuid bit set: the binary runs with the effective UID of its owner (usually root), while the real UID remains that of the calling user. The kernel tracks both because different operations check different identities. File access checks the effective UID (so the program can act with the owner's permissions); signalling and accounting use the real UID (so a program cannot use elevated privileges to hide its true origin).

Question 9

Why does the kernel use copy-on-write when implementing fork?

Show answer
To avoid physically copying the parent's entire address space when a child is created. Copy-on-write marks the parent's writable pages as read-only and shares them with the child. Neither process can write to the shared pages, so both observe the same content. When either process tries to write, the kernel copies just that page and updates the writer's page table. This is efficient because most children immediately call exec, which discards the child's entire address space — with copy-on-write, the kernel never had to copy it.

Question 10

What is a zombie process, and how is it cleaned up?

Show answer
A zombie is a process that has terminated but whose exit status has not yet been collected by its parent. The kernel keeps a minimal entry in the process table (PID and exit status) so that the parent's wait call can retrieve it. The entry is removed when the parent calls wait, or (if the parent dies first) when the process is reparented to PID 1, which reaps it. A parent that never reaps its children accumulates zombies until the process table is exhausted.

Question 11

Which of the following is the correct ordering of the three-level scheduler model from the process's perspective?

Show answer
The second choice. A process first passes through the long-term scheduler, which admits it to the ready queue. The short-term scheduler then dispatches it to the CPU. The medium-term scheduler may later swap it out to disk (and back) if memory pressure requires. The three schedulers run on very different timescales — the long-term scheduler once per admission, the short-term scheduler hundreds of times per second, the medium-term scheduler as memory pressure dictates.

Question 12

Which of the following is NOT one of the four points at which a scheduling decision is required?

Show answer
When a system call is executed. Not every system call requires a scheduling decision — only ones that cause a state transition (like blocking or terminating). A non-blocking system call (such as getpid) may complete without the scheduler running at all. The four decision points are: process blocks, process is preempted, blocked process becomes ready, process terminates.

Question 13

Which scheduling metric measures the time from submission to first output?

Show answer
Response time. It measures when the process first produces output, as opposed to turnaround time, which measures when it finishes. Response time is the primary metric for interactive systems; turnaround time is the primary metric for batch systems. Waiting time is a different metric: it measures time spent in the ready queue only, excluding blocked time.

Question 14

Three processes arrive at t = 0 with burst times 3, 6, and 9. They run in that order (FCFS). Compute average waiting time.

Show answer
Wait times: P1 = 0, P2 = 3, P3 = 9. Average = (0 + 3 + 9) / 3 = 4.0. Turnarounds: 3, 9, 18; average = 10. If the processes ran shortest-first (they are already sorted), the wait times would be the same. If they arrived in the order 9, 6, 3, FCFS would produce wait times 0, 9, 15 (average 8.0), while shortest-first would produce 0, 3, 9 (average 4.0).

Question 15

What is the fundamental difference between preemptive and non-preemptive scheduling?

Show answer
A preemptive scheduler can interrupt a running process at any time — typically on a timer tick or when a higher-priority process becomes ready. The process is moved from Running to Ready involuntarily. A non-preemptive scheduler allows a running process to continue until it voluntarily yields (by blocking or terminating). Non-preemptive is simpler but vulnerable to a CPU-bound process that monopolises the CPU. Modern general-purpose kernels are preemptive.

Question 16

Why does the scheduler typically favour I/O-bound processes when they become ready?

Show answer
An I/O-bound process has just completed an I/O operation and is ready to run a brief CPU burst — typically processing the data that arrived and issuing the next request. If the scheduler dispatches it promptly, it will use a small amount of CPU and then block again, freeing the CPU for other processes and keeping the I/O device busy. Delaying it wastes the device as well as the CPU. This is a direct consequence of the CPU–I/O burst model: I/O-bound processes naturally give up the CPU quickly, so favouring them costs little and improves both CPU and device utilisation.

Question 17

Which of the following is a key difference between a context switch and a mode switch?

Show answer
The second choice. A mode switch changes the CPU's privilege level — user mode to kernel mode or back — but keeps the same process running. A context switch changes which process is running, saving one process's state and restoring another's. A context switch involves two mode switches plus the save-and-restore work in between, so it is strictly larger and more expensive than a mode switch.

Question 18

A round-robin scheduler uses a 50 μs quantum. The measured context-switch cost (direct) is 4 μs. What fraction of CPU time is spent on context switching?

Show answer
Each process runs for 50 μs, then the system spends 4 μs switching. Of every 54 μs, 4 μs is overhead = about 7.4%. This ignores the indirect cost (cache and TLB pollution), which would raise the effective overhead substantially. For a system with a heavier workload or a smaller quantum, the percentage would be larger still — a reason why quanta cannot be arbitrarily small.

Question 19

Why is a thread context switch cheaper than a process context switch?

Show answer
Because threads in the same process share one address space. When switching between threads, the kernel does not need to change the page-table base in the MMU, does not need to flush or retag the TLB, and does not lose cache locality — the incoming thread is likely to find much of what it needs already in the cache. Only the registers and stack pointer need to be swapped. Between processes, all three memory-related costs apply. On modern hardware with ASIDs (or PCIDs on x86) the difference is somewhat smaller than it once was, but thread switches remain noticeably cheaper.

Question 20

What is the difference between a voluntary and an involuntary context switch, and what does a high rate of each indicate?

Show answer
A voluntary switch occurs when a process blocks — it chose to give up the CPU. A high rate indicates an I/O-bound workload: the process runs briefly, blocks on I/O, and yields the CPU each time. An involuntary switch occurs when the process is preempted. A high rate indicates a CPU-bound workload in a contended system: the process would prefer to keep running, but the scheduler takes the CPU away. The ratio between the two counters is a useful classifier for a process's workload profile.

Question 21

What does the "process context" include, and why does the term encompass more than the PCB?

Show answer
The process context is the full set of information needed to run the process: the register state (which lives in the PCB), the address space (described by the page table referenced from the PCB), and the kernel's bookkeeping structures (open file table, credentials, signal handlers) which are also referenced from the PCB. The term encompasses more than the PCB itself because the PCB does not physically hold these large structures — it points to them. When the kernel performs a context switch, all of these pieces must become the current ones, not just the registers.

Question 22

Why does a heavy context-switch load reduce the effective performance of a CPU-bound process even though the process itself spends the same amount of CPU time on its work?

Show answer
Because of two effects. First, the direct overhead of the switches themselves consumes CPU time that would otherwise be spent on the workload — that time appears as system time in the process's accounting. Second, and more important, the indirect overhead of cache and TLB pollution degrades the process's performance when it is running: its working set was evicted during the switch, so the first accesses after resuming miss in caches and in the TLB, each miss costing many cycles. The process's own CPU time remains the same, but the wall-clock time to complete the same work increases. On a heavily loaded system, this indirect cost can dominate.

Question 23

Which of the following commands would show you both the voluntary and involuntary context-switch counts for a given process?

(a) ps -ef | grep <pid>
(b) cat /proc/<pid>/stat
(c) top -p <pid>
(d) ls /proc/<pid>
Show answer
The best answer is (b) cat /proc/<pid>/stat. Fields 42 and 43 of that file give the voluntary and involuntary switch counts. The same counters also appear in /proc/<pid>/status as voluntary_ctxt_switches and nonvoluntary_ctxt_switches. ps -ef does not show switch counts by default, top shows only CPU and memory, and ls /proc/<pid> just lists the entries in that directory.

Question 24

Describe the fork / exec / wait cycle in two or three sentences, and explain why the split between fork and exec is useful.

Show answer
A shell (or any parent process) creates a new process by calling fork, which duplicates the parent. The child then calls one of the exec family, which replaces the child's address space with a new program. The parent calls wait to block until the child terminates and to reap its exit status. The split between fork and exec is useful because it gives the child a chance to modify its environment between the two calls — change directory, redirect file descriptors, set resource limits, drop privileges — before the new program starts. This is how the shell implements redirection and pipelines, and how privileged programs drop root privileges before executing untrusted code.

Question 25

In what sense is the "simultaneous execution" of many processes on a single-core CPU an illusion, and what mechanism creates it?

Show answer
On a single-core CPU, only one process executes at any instant. The apparent simultaneity is an illusion created by the context switch: the kernel rapidly alternates between processes, giving each a brief time slice. Switches happen hundreds or thousands of times per second — far faster than a human can perceive — and most processes block on I/O frequently, so the CPU is dispatched to each process precisely when it has work to do. The user never sees the switching; they see the aggregate output of many processes, which appears as continuous multi-tasking.

Ready for the graded quiz?

Once you are comfortable with every question above, take the graded Unit 3 quiz in the LMS. It covers the same material with a mix of multiple-choice, short-answer, and worked problems on scheduling metrics.

👤