CSC264 Operating Systems

Operating SystemsUnit 25 min read

Process Management: Concepts, Scheduling, IPC, and Synchronization

Unit 2 of Operating Systems: This unit provides a comprehensive exploration of process management, covering the process lifecycle, CPU scheduling algorithms, inter-process communication (IPC) mechanisms, critical section problems, and synchronization primitives essential for OS design.

Key points

  • Processes are active entities representing programs in execution, managed by the OS through Process Control Blocks (PCBs).
  • CPU scheduling algorithms determine the order of process execution to optimize metrics like turnaround time and waiting time.
  • Race conditions occur when multiple processes access shared data concurrently, necessitating synchronization.
  • Inter-process communication (IPC) enables data exchange between processes via shared memory or message passing.
  • Synchronization tools like semaphores and monitors are used to enforce mutual exclusion and prevent inconsistent data states.

The Process Concept

A process is a program in execution. It is more than just program code; it includes the current activity, represented by the value of the program counter, stack (temporary data), and data section (global variables).

Process Control Block (PCB)

Each process is represented in the OS by a PCB, which contains:

  • Process State: (New, Ready, Running, Waiting, Terminated).
  • Program Counter: Address of the next instruction.
  • CPU Registers: Accumulators, index registers, stack pointers.
  • CPU Scheduling Information: Priority and scheduling queue pointers.
  • Memory Management Information: Page tables or segment tables.

CPU Scheduling

The objective of multiprogramming is to have some process running at all times to maximize CPU utilization.

Scheduling Algorithms

  1. First-Come, First-Served (FCFS): Simplest; processes are executed in the order they arrive.
  2. Shortest Job First (SJF): Selects the process with the smallest burst time. It is optimal for minimizing average waiting time.
  3. Shortest Remaining Time Next (SRTN): The preemptive version of SJF.
  4. Round Robin (RR): Designed for time-sharing systems; each process gets a small unit of CPU time (time quantum).
  5. Priority Scheduling: Each process is assigned a priority; the CPU is allocated to the process with the highest priority.

Worked Example: SRTN vs. SJF

Consider the following processes:

Process Arrival Time Burst Time
P0 0 7
P1 2 4
P2 4 1
P3 5 4

SJF (Non-preemptive):

  1. At t=0, only P0 is available. P0 runs until t=7.
  2. At t=7, P1, P2, and P3 have arrived.
  3. Order based on burst time: P2 (1), P1 (4), P3 (4).
  • Waiting Times: P0=0, P2=7-4=3, P1=8-2=6, P3=12-5=7.
  • Average Waiting Time = (0+3+6+7)/4 = 4.0.

SRTN (Preemptive):

  1. t=0: P0 starts.
  2. t=2: P1 arrives. P0 remaining=5, P1=4. P1 takes over.
  3. t=4: P2 arrives. P1 remaining=2, P2=1. P2 takes over.
  4. t=5: P2 finishes. P3 arrives. Remaining: P0=5, P1=2, P3=4. P1 takes over.
  5. t=7: P1 finishes. Remaining: P0=5, P3=4. P3 takes over.
  6. t=11: P3 finishes. P0 takes over.
  • Waiting Times: P0=(2-0)+(11-7)=6, P1=(4-2)=2, P2=(4-4)=0, P3=(7-5)=2.
  • Average Waiting Time = (6+2+0+2)/4 = 2.5.

Inter-Process Communication (IPC)

Processes can be independent or cooperating. Cooperating processes require IPC.

  • Shared Memory: Processes read/write to a shared region of memory. Fast, but requires synchronization.
  • Message Passing: Processes communicate via system calls (send, receive). Useful for distributed systems.

Process Synchronization

When multiple processes access shared data concurrently, a Race Condition may occur, where the final result depends on the specific order of execution.

The Critical Section Problem

The critical section is a segment of code where a process accesses shared resources. To solve this, a solution must satisfy:

  1. Mutual Exclusion: Only one process can be in its critical section at a time.
  2. Progress: If no process is in the critical section, the decision of who enters next cannot be postponed indefinitely.
  3. Bounded Waiting: There must be a limit on the number of times other processes are allowed to enter their critical sections after a process has made a request.

Synchronization Primitives

  • Semaphores: An integer variable accessed via two atomic operations: wait() (P) and signal() (V).
    • Counting Semaphores: Range over an unrestricted domain.
    • Binary Semaphores: Range only between 0 and 1 (Mutex).
  • Busy Waiting: A process repeatedly checks a condition in a loop. This wastes CPU cycles.
  • Sleep and Wakeup: Instead of busy waiting, a process can block itself (sleep) and be awakened by another process (wakeup) when the condition changes, improving efficiency.

Comparison Table: Scheduling Algorithms

Algorithm Preemptive Advantage Disadvantage
FCFS No Simple, fair Convoy effect
SJF No Optimal waiting time Starvation for long jobs
RR Yes Good for interactive High overhead if quantum is small
Priority Both Handles importance Starvation

System Calls

System calls provide the interface between a process and the OS.

  1. Process Control: fork(), exec(), exit().
  2. File Management: open(), read(), write().
  3. Device Management: ioctl(), read().

When a system call is made, the CPU switches from user mode to kernel mode via a software interrupt (trap). The OS examines the system call number, executes the corresponding kernel function, and returns to user mode.

Exam Tip

  • Numerical Problems: Always draw a Gantt chart for scheduling problems. It makes calculating waiting/turnaround times much less prone to error.
  • Conceptual Questions: When asked about "Starvation," always mention that it is a result of indefinite blocking, often caused by priority scheduling or SJF, and can be solved by "Aging" (gradually increasing the priority of waiting processes).
  • Definitions: Keep definitions concise. For "System Calls," mention the mode switch (User to Kernel) as it is the most critical technical detail.

Based on the TU BSc CSIT syllabus for Operating Systems (CSC264), unit 2.

Discussion

Loading…