Operating Systems: Process Management, Memory, and Kernel Modes

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/125

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:34 AM on 10/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

126 Terms

1
New cards

HW2 Q: Which is SHARED by all threads in a process? A) registers B) stack C) global variables D) program counter

C) Global variables (each thread has its own registers, PC and stack)

2
New cards

HW2 Q: What is an upcall?

A message from the kernel to the upcall handler in the thread library telling it about an event (e.g., a thread is about to block). Part of scheduler activations

3
New cards

HW2 Q: What is the purpose of the PCB?

Stores everything the OS needs to manage a process: state, PID, program counter, CPU registers, scheduling, memory, accounting and I/O info

4
New cards

HW2 Q: What does fork() do? A) Terminates a process B) Creates a new process C) Replaces memory D) Waits for a child

B) Creates a new process (a copy of the parent)

5
New cards

HW2 Q: A process that has terminated but whose parent has not yet called wait() is a(n) ____

Zombie process

6
New cards

HW2 Q: Circular buffer FULL condition

((in + 1) % BUFFER_SIZE) == out

7
New cards

HW2 Q: Circular buffer EMPTY condition

in == out

8
New cards

HW2 Q: Which is NOT a benefit of multithreading? (Responsiveness / Resource sharing / Economy / Uses more memory)

Uses more memory. Threads use LESS memory than processes (that is the Economy benefit)

9
New cards

HW2 Q: Running more than one task at exactly the same time on multiple cores is ____

Parallelism (interleaving tasks over time is concurrency)

10
New cards

HW2 Q: In which model does one blocking system call block ALL threads, and threads cannot run in parallel on multicore?

Many-to-One

11
New cards

HW2 Q: Two advantages of a thread pool

1) Reusing an existing thread is faster than creating a new one 2) Limits how many threads exist at once

12
New cards

Operating system (definition)

Software that acts as an intermediary between the user and the hardware; controls and coordinates hardware use among programs and users

13
New cards

Monolithic structure (+ / -)

Whole kernel is one binary in one address space (original UNIX). + Fast, little overhead. - Hard to implement, extend and debug

14
New cards

Layered approach (+ / -)

Layer 0 = hardware, layer N = user interface; each layer uses only lower layers. + Easy to build and debug. - Poor performance (calls pass through many layers)

15
New cards

Q: The major difficulty in designing a layered OS is ____

Appropriately defining the various layers

16
New cards

Microkernel (+ / -)

Kernel keeps only essential services; the rest runs in user space; communicates by message passing. + Easy to extend, reliable, secure. - Message-passing overhead. Example: Mach

17
New cards

Q: A microkernel is a kernel ____

That is stripped of all nonessential components

18
New cards

Loadable kernel modules (modular approach)

Kernel has a core set of components and links in extra services (modules) at boot or run time, each with a known interface. Used by Linux, macOS, Solaris

19
New cards

Modular approach: ADVANTAGES

Load/unload services dynamically without recompiling the kernel; any module can call any other directly; faster than microkernel (no message passing); flexible like layered

20
New cards

Modular approach: DISADVANTAGES

Modules still run in kernel mode, so a buggy module can crash the whole system; less isolation/protection than a microkernel; kernel can grow large

21
New cards

Q: ____ allows operating system services to be loaded dynamically

Modules (loadable kernel modules)

22
New cards

Dual-mode operation (purpose)

User mode and kernel mode; protects the OS and system components from accidental or malicious user programs

23
New cards

User mode

Mode bit = 1; applications run here; privileged instructions are NOT allowed

24
New cards

Kernel mode

Mode bit = 0; OS code runs here; privileged instructions ARE allowed

25
New cards

Mode bit

Hardware bit showing the current mode: 0 = kernel, 1 = user

26
New cards

How does the CPU switch from user mode to kernel mode?

A system call, trap or interrupt sets the mode bit to kernel; returning from it sets the bit back to user

27
New cards

Q: Another term for kernel mode? A) supervisor B) system C) privileged D) All of the above

D) All of the above

28
New cards

Q: Which should run ONLY in kernel mode? Read the clock / Clear memory / Issue an instruction / Turn off interrupts / Modify device-status table

Clear memory, Turn off interrupts, Modify device-status table

29
New cards

What happens if a user program tries a privileged instruction?

Hardware does not run it; it traps to the OS, which treats it as illegal (usually terminates the program)

30
New cards

Q: A ____ prevents a user program from never returning control to the OS

Timer

31
New cards

T/F: System calls can be run in either user mode or kernel mode

False. Called from user mode, executed in kernel mode

32
New cards

T/F: Interrupts may be triggered by either hardware or software

True

33
New cards

System call

Programming interface to the services provided by the OS; runs in kernel mode

34
New cards

API (Application Programming Interface)

Set of functions a programmer calls; the API function invokes the actual system call. Examples: Windows API, POSIX API (UNIX/Linux/macOS), Java API

35
New cards

Why use an API instead of calling system calls directly?

Portability (same code on any system with that API) and simplicity (system calls are more detailed/harder to use)

36
New cards

T/F: The system call interface is the boundary between user programs and OS services

True

37
New cards

Q: ____ is NOT a technique for passing parameters to a system call. A) Cache memory B) Registers C) Stack D) Block in memory

A) Cache memory

38
New cards

Process

A program in execution; ACTIVE entity

39
New cards

Program

PASSIVE entity: an executable file on disk; becomes a process when loaded into memory

40
New cards

Process memory layout, top (high address) to bottom (low address)

Stack -> (free space) -> Heap -> Data -> Text

41
New cards

Text section

Holds the executable program code

42
New cards

Data section

Holds global (and static) variables

43
New cards

Heap

Memory allocated dynamically at run time (malloc/new); grows UP toward the stack

44
New cards

Stack

Temporary data: function parameters, return addresses, local variables; grows DOWN toward the heap

45
New cards

Q: Function parameters, return addresses and local variables are stored in the ____

Stack

46
New cards

Q: A global variable is stored in the ____ section

Data section

47
New cards

Q: Memory from malloc() comes from the ____

Heap

48
New cards

Q: Which sections are fixed size and which grow?

Text and data are fixed size. Stack and heap grow and shrink during execution

49
New cards

5 process states

New, Ready, Running, Waiting, Terminated

50
New cards

Process state transitions

New->Ready (admitted); Ready->Running (scheduler dispatch); Running->Ready (interrupt); Running->Waiting (I/O or event wait); Waiting->Ready (I/O or event done); Running->Terminated (exit)

51
New cards

Q: A process may move to Ready by A) I/O completion B) awaiting its CPU turn C) being newly admitted D) All of the above

D) All of the above

52
New cards

Process Control Block (PCB)

Kernel data structure for each process: state, PID, program counter, registers, scheduling, memory, accounting, I/O info. Linux: task_struct

53
New cards

Context switch

CPU switches from one process to another: SAVE the old process's state into its PCB, then LOAD the new process's state from its PCB

54
New cards

Q: A ____ saves the state of the current process and restores the state of the next process

Context switch

55
New cards

When does a context switch happen?

On an interrupt, a system call, a timer/time-quantum expiring, or when the running process waits for I/O

56
New cards

fork() return values

0 in the child; the child's PID (> 0) in the parent; negative if fork failed

57
New cards

Which UNIX system call CREATES a new process?

fork()

58
New cards

Which system call REPLACES a process's memory with a new program?

exec() (used after fork(); if it succeeds it never returns)

59
New cards

wait()

Parent waits for a child to finish; returns the child's PID and exit status

60
New cards

Orphan process

Child whose parent terminated without calling wait(); init (systemd) becomes its parent

61
New cards

Q: The ____ process becomes the parent of orphan processes

init (systemd)

62
New cards

Q: When a child process is created, which is possible? A) Runs concurrently with parent B) New program loaded C) Duplicate of parent D) All of the above

D) All of the above

63
New cards

Thread

Basic unit of CPU utilization: thread ID, program counter, register set and stack

64
New cards

What does each thread have of its OWN?

Thread ID, program counter, register set, stack

65
New cards

What do threads in a process SHARE?

Code (text), data (globals), heap, open files and other OS resources

66
New cards

T/F: A thread is composed of a thread ID, program counter, register set, and heap

False (stack, not heap)

67
New cards

4 benefits of multithreading

Responsiveness, resource sharing, economy, scalability

68
New cards

Concurrency

Multiple tasks make progress by interleaving; possible on a single core

69
New cards

Parallelism

Multiple tasks run at the same time; requires multiple cores

70
New cards

T/F: It is possible to have concurrency without parallelism

True

71
New cards

User threads

Managed by a user-level thread library without kernel support

72
New cards

Kernel threads

Supported and managed directly by the OS kernel

73
New cards

Many-to-One model

Many user threads -> 1 kernel thread. One blocking call blocks all; no parallelism on multicore. Rarely used

74
New cards

One-to-One model

Each user thread -> its own kernel thread. More concurrency and parallelism; too many kernel threads burden the system. Linux and Windows

75
New cards

Many-to-Many model

Many user threads multiplexed onto a smaller or equal number of kernel threads

76
New cards

Two-level model

Like many-to-many, but also lets a user thread be bound to one kernel thread

77
New cards

Q: Which model do Linux and Windows use?

One-to-One

78
New cards

3 main thread libraries

POSIX Pthreads, Windows threads, Java threads

79
New cards

Pthreads

POSIX standard API for thread creation and synchronization; a specification, implemented at user or kernel level

80
New cards

pthread_create()

Creates a new thread that runs a given function

81
New cards

pthread_join()

Waits for a thread to terminate (like wait() for processes)

82
New cards

Thread pool

Creates threads in advance; they wait for work and are reused instead of creating a new thread per task

83
New cards

Scheduler activations

Kernel gives the app LWPs and informs the thread library of events via upcalls

84
New cards

Amdahl's Law formula

Speedup

85
New cards

Amdahl: what happens as N goes to infinity?

Speedup approaches 1 / S; the serial part limits the maximum gain

86
New cards

CPU scheduler (short-term scheduler)

Selects a process from the ready queue and allocates the CPU to it

87
New cards

Dispatcher

Gives the CPU to the selected process: context switch, switch to user mode, jump to the right place in the program

88
New cards

Nonpreemptive scheduling

Once a process has the CPU it keeps it until it terminates or waits

89
New cards

Preemptive scheduling

The OS can take the CPU away from a running process (e.g., time quantum expires)

90
New cards

Turnaround time formula

Completion time - Arrival time

91
New cards

Waiting time formula

Turnaround time - Burst time

92
New cards

Response time

Time from submission until the first response (first time on CPU)

93
New cards

Q: ____ is the number of processes completed per time unit

Throughput

94
New cards

FCFS

First-come, first-served; FIFO ready queue; nonpreemptive

95
New cards

Convoy effect

In FCFS, short processes wait behind one long process

96
New cards

SJF

Run the process with the shortest next CPU burst; optimal (minimum) average waiting time

97
New cards

SJF next-burst prediction formula

tau(n+1) = alpha * t(n) + (1 - alpha) * tau(n); usually alpha = 1/2

98
New cards

Round Robin (RR)

Each process gets a time quantum q, then is preempted and goes to the back of the ready queue. Designed for time-sharing

99
New cards

RR: what if q is too large or too small?

Too large = becomes FCFS. Too small = too many context switches (overhead). Rule: about 80% of CPU bursts should be shorter than q

100
New cards

Priority scheduling

CPU goes to the highest priority (smallest number). Problem: starvation. Fix: aging (raise priority of long-waiting processes)