Operating Systems Exam Preparation: Core Concepts

CPU Scheduling Fundamentals

CPU scheduling is the process by which the operating system selects which process to execute next. Algorithms aim to optimize metrics such as waiting time, turnaround time, and response time.

Key Performance Metrics

  • Completion Time (CT): The moment a process finishes.
  • Turnaround Time (TAT): TAT = Completion Time - Arrival Time
  • Waiting Time (WT): WT = Turnaround Time - Burst Time
  • Response Time (RT): RT = First time it runs - Arrival Time

Base Example Data

ProcessArrivalBurst
P106
P213
P328
P434

Scheduling Algorithms

1. FCFS (First Come First Served)

Processes execute in order of arrival. Non-preemptive.

2. SJF (Shortest Job First)

Selects the process with the smallest burst time. Non-preemptive. Risk: Starvation for long processes.

3. SRTF (Shortest Remaining Time First)

Preemptive version of SJF. If a new process has a shorter remaining time than the current one, it interrupts.

4. Round Robin

Each process uses the CPU for a fixed quantum. If it doesn’t finish, it returns to the end of the queue.

Bash Scripting for Exams

1. Sum from 1 to N

sum=0
for ((i=1; i<=$1; i++)); do
  sum=$((sum + i))
done
echo $sum

2. Count Files in Directory

count=0
for f in *; do
  if [ -f "$f" ]; then
    count=$((count+1))
  fi
done
echo $count

3. Compare Two Numbers

if [ "$1" -gt "$2" ]; then
  echo "First is greater"
elif [ "$1" -lt "$2" ]; then
  echo "Second is greater"
else
  echo "Equal"
fi

Memory Management

Page Replacement

Determines which page to remove when memory is full. Common algorithms: FIFO, LRU (uses history), and OPT (uses future).

Address Translation

Converts virtual addresses to physical addresses using a page table. Physical = Frame * Size + Offset.

TLB (Translation Lookaside Buffer)

A fast cache for virtual-to-physical mappings. A TLB Hit significantly reduces memory access time compared to a TLB Miss.

Concurrency and Synchronization

Threads and Race Conditions

A race condition occurs when multiple threads modify shared data concurrently without synchronization, leading to unpredictable results because operations are not atomic.

Semaphores

Synchronization variables modified via wait() (decrement) and signal() (increment). Used for mutual exclusion or resource coordination.

Deadlock

A state where processes are blocked waiting for resources held by others. Requires four conditions: Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait.

Monitors

High-level synchronization constructs using condition variables. Always use while loops when checking conditions to handle state changes after waking up.

Readers–Writers Problem

Manages concurrent access to shared data. Strategies include Reader Priority, Writer Priority, or Fair access to prevent starvation.