Understanding Process Management in Operating Systems

What is a Process?

A process is a running program. When a process is in a ready state, the only thing that’s missing is the allocation of the processor.

Process States

The completed state of a process always comes from the state of execution.

Reasons for a Suspended Process State

A suspended state exists to incorporate more ready processes, preventing the internal memory to the processor from being occupied for too long. This increases system productivity by allowing a larger number of processes to be handled over time.

Difference Between Ready-Suspended and Blocked-Suspended States

The key difference is that a process in the ready-suspended state can run, while a process in the blocked-suspended state cannot.

Reasons for Process Termination

At least four reasons justify the termination of a process:

  • Normal completion
  • Time limit exceeded
  • Unavailable memory
  • Violation of memory limits
  • Arithmetic error
  • Maximum waiting time exceeded

Process Control Block (BCP)

The BCP (Process Control Block) is the information needed by the operating system to manage the process.

UNIX Process States

Specific states in the UNIX process map include:

  • Execution in user mode
  • Kernel mode
  • Ready to run in memory
  • Asleep in memory
  • Ready to run and discharged
  • Expelled
  • Created
  • Zombie

Reasons for Process Creation

Two reasons for the creation of a process are:

  1. New batch job
  2. Interactive login

Process Image

The image of a process collects information about the user program and the data that the user has to handle. It includes the control block, the system stack, the program to be executed, and the data.

Processor Schedulers

Types of Schedulers

There are three main types of schedulers:

  • Long-term scheduler: Incorporates processes into internal memory to balance CPU-intensive processes and input/output.
  • Medium-term scheduler
  • Short-term scheduler: Decides which process will be allocated to the processor next.

Frequency of Scheduler Execution

The short-term scheduler runs most frequently, while the medium-term scheduler runs less frequently.

Scheduler Criteria

User-Oriented Criteria

  • Turnaround time
  • Response time
  • Deadlines
  • Predictability

System-Oriented Criteria

  • Throughput
  • Processor utilization
  • Fairness
  • Priority enforcement
  • Resource balancing

Starvation

Starvation is a condition where a process is indefinitely delayed because other processes are always given preference.

Round-Robin Scheduling

The Round-Robin algorithm allocates the processor sequentially to various processes that can run during a specific time quantum.

Priority Algorithm Issues

The priority algorithm can lead to starvation, where a low-priority process may never be executed.

Process Execution Modes

There are two modes of process execution:

  • User mode
  • System mode (kernel mode)

Mode Change vs. Process Change

A mode change is a change in the process’s state (e.g., ready, suspended), while a process change involves switching the currently running process with another process.

Interrupts and Traps

An interrupt is caused by an external event independent of the running process. A trap is an error or exception generated within the running process, such as an illegal file access attempt.

Threads

In modern operating systems, a process can be divided into multiple threads. Each thread handles specific information within the process.

Thread States

A thread can be in various states, similar to a process.

Deadlock

A deadlock occurs when two or more processes are blocked indefinitely, waiting for resources held by each other.

Wait-For Graph

A wait-for graph represents processes and their dependencies on resources. It is used to detect potential deadlocks.

It consists of a graph of processes and their relationships so that we can identify the dependencies between processes and hence determine the possible loops or deadlocks between them.

Safe State

A system is in a safe state if there is at least one sequence in which all processes can complete by acquiring their needed resources.

Actions in a Safe State

If the processing of an application for a process detects that the system is in a safe state, the following actions should be performed:

Available = Available – Request

Assigned = Assigned + Request

Need = Need – Request

Preventing Retain and Wait

Preventing the “retain and wait” condition is generally not feasible as it would significantly limit system productivity and could lead to starvation. Retaining and hope can be solved but it is not appropriate to do so in 2 ways: in each process to allocate all the resources you will need from the outset, taking into account that a process can not be done with a resource that needs to get rid of the rest of resources be allocated.

Resource Allocation Graph Example

Consider the following resource allocation graph:

P = {P1, P2, P3, P4}

R = {r1, r2, r3, r4, r5, r6}

E = {(P1, r1), (P2, r4), (P2, r5), (P3, r6), (P4, r2), (r1, P2), (r2, P1), (r3, P2), (r4, P4), (r5, P3), (r6, P2)}

There are deadlocks: P2 – P4 – P1 – P2 and P2 – P3 – P2.

Image

Image

Image

Image