Operating System Process Management and Scheduling

Posted by Anonymous and classified in Computers

Written on in English with a size of 7.04 KB

Process Management Fundamentals

Process Management is one of the most critical responsibilities of an Operating System. While a program is just a passive collection of instructions stored on a disk, a process is an active, executing instance of that program.

Process Concepts & The Process Control Block

When a program is loaded into memory to execute, it becomes a process. A process is structurally divided into four distinct memory sections:

  • Text Section: Contains the compiled, executable machine code.
  • Data Section: Stores global and static variables.
  • Heap Section: Memory dynamically allocated during runtime (e.g., using malloc() in C or new in C++).
  • Stack Section: Temporary data storage for function parameters, return addresses, and local variables.

The Process Control Block (PCB)

To manage these processes, the OS creates a data structure for each one called a Process Control Block (PCB) (also known as a Task Control Block). The PCB acts as the identity card for a process, containing all the information needed to manage it.

Key attributes stored in a PCB include:

  • Process ID (PID): A unique identifier assigned by the OS.
  • Process State: The current condition of the process (e.g., New, Ready, Running).
  • Program Counter (PC): Contains the address of the next instruction to be executed.
  • CPU Registers: Information saved when the process switches out, including accumulators and index registers.
  • Memory-Management Information: Includes page tables or segment tables.
  • I/O Status Information: A list of open files and allocated I/O devices.

Process States

As a process executes, it changes status. The lifecycle of a process typically transitions through five classic states:

  1. New: The process is being created or loaded from disk.
  2. Ready: The process is in main memory, waiting to be assigned to a processor.
  3. Running: Instructions are currently being executed by the CPU.
  4. Waiting (Blocked): The process is waiting for an event to occur (e.g., I/O completion).
  5. Terminated: The process has finished execution, and the OS is cleaning up resources.

Context Switching

When the CPU switches from one process to another, the OS saves the current state of the old process in its PCB and loads the new process state. This is called a Context Switch, which represents pure overhead.

Operations on Processes

Operating systems provide mechanisms for process creation and termination.

Process Creation

A process can create new processes, forming a tree structure. The creator is the parent process, and the new process is the child process.

  • In UNIX-like systems, a child is created using the fork() system call, which duplicates the parent's address space. The exec() system call is then used to load a new program.
  • The parent can wait for the child to finish (wait()) or run concurrently.

Process Termination

A process terminates via the exit() system call.

  • Zombie Process: A process that has finished but remains in the process table because the parent has not yet read its exit status.
  • Orphan Process: A process whose parent has terminated. The OS adopts it, usually assigning it to the root init or systemd process.

Inter-Process Communication (IPC)

Processes executing concurrently may be independent or cooperating. Cooperating processes use Inter-Process Communication (IPC) to share data.

Levels of Scheduling

Scheduling levels control how processes move between memory, the CPU, and storage.

  • Long-Term Scheduler (Job Scheduler): Selects processes from the job pool on disk and loads them into memory.
  • Medium-Term Scheduler: Handles swapping processes between main memory and secondary storage to manage memory pressure.
  • Short-Term Scheduler (CPU Scheduler): Selects a process from the ready queue and allocates the CPU.

Scheduling Criteria

Performance metrics include:

  • CPU Utilization: Percentage of time the CPU is busy.
  • Throughput: Number of completed processes per unit of time.
  • Turnaround Time: Total time from submission to completion.
  • Waiting Time: Total time spent in the ready queue.
  • Response Time: Time from submission until the first response.

Optimization Goal: Maximize utilization and throughput; minimize turnaround, waiting, and response times.

Scheduling Algorithms

Algorithms can be non-preemptive or preemptive.

1. First-Come, First-Served (FCFS)

Processes are executed in arrival order. Downside: The Convoy Effect, where short processes wait behind long ones.

2. Shortest Job First (SJF)

Executes the process with the smallest next CPU burst. Preemptive SJF is known as Shortest Remaining Time First (SRTF). Downside: Potential starvation for long processes.

3. Priority Scheduling

Allocates the CPU to the highest-priority process. Solution to starvation: Aging, which increases the priority of waiting processes over time.

4. Round Robin (RR)

Uses a time quantum. If a process doesn't finish within its quantum, it is moved to the back of the ready queue.

5. Multilevel Queue Scheduling

Partitions the ready queue based on process properties (e.g., foreground vs. background).

6. Multilevel Feedback Queue

Allows processes to move between queues based on CPU usage, providing a flexible and complex scheduling system.

Multiple-Processor Scheduling

  • Asymmetric Multiprocessing: One master processor handles scheduling; others execute user code.
  • Symmetric Multiprocessing (SMP): Each processor schedules itself.
  • Processor Affinity: Processes prefer the processor they are currently running on to maintain cache efficiency.
  • Load Balancing: Distributes workloads via Push migration or Pull migration.

Algorithm Evaluation

Deterministic Modeling

Uses a static, predetermined workload to calculate exact performance metrics for different algorithms.

Related entries: