Chapter 3: Processes

Process Concept and State Diagram

A process is a program in execution. It consists of the program code, current activity, and the associated resources (such as memory, files, and I/O devices).

Key aspects: - A process has its own program counter, stack, and data section. - It represents the basic unit of work in a system.

Process State Diagram A process moves between different states during execution:

  • New: Process is being created.

  • Ready: Process is waiting to be assigned to the CPU.

  • Running: Instructions are being executed on the CPU.

  • Waiting/Blocked: Process is waiting for some event (e.g., I/O completion).

  • Terminated: Process has finished execution.

Process Control Block (PCB)

The Process Control Block (PCB) is a data structure maintained by the operating system to represent a process. It stores essential information needed to manage the process.

Contents of PCB typically include: - Process ID (PID) - Process state - Program counter - CPU registers - CPU scheduling information - Memory management information - I/O status information - Accounting information

Process Scheduling Queues

The operating system maintains different queues to manage processes:

  • Job Queue: Set of all processes in the system.

  • Ready Queue: Processes in main memory, ready to execute, waiting for CPU time.

  • Device Queue: Processes waiting for I/O devices.

Schedulers: - Long-term scheduler: Selects which jobs are admitted into the system for processing. - Medium-term scheduler: Temporarily suspends or resumes processes. - Short-term scheduler: Selects which process will be executed next on the CPU.

Context Switching

Context switching occurs when the CPU switches from one process to another.

Steps involved: 1. Save the state of the current process (into its PCB). 2. Load the state of the next process (from its PCB). 3. Resume execution of the new process.

Key points: - Context switching adds overhead because the system does not do useful work while switching. - Efficient context switching is critical for system performance.