OS Concepts: RTOS, Critical Section, Memory & Deadlocks

Posted by Anonymous and classified in Computers

Written on in English with a size of 5.51 KB

Real-Time Operating System (RTOS)

A Real-Time Operating System (RTOS) is an operating system that provides a response within a specified time limit. It is used in applications where timing is critical.

Types of RTOS

  • Hard Real-Time OS: The deadline must be met. Missing a deadline may lead to system failure.
  • Soft Real-Time OS: Occasional delays are acceptable, but performance may be affected.

Applications of RTOS

  • Medical Equipment
  • Robotics
  • Air Traffic Control Systems
  • Industrial Automation
  • Automobile Control Systems

Advantages of RTOS

  • Fast response
  • High reliability
  • Predictable performance

Critical Section

A Critical Section is the part of a program where a process accesses or modifies shared data or resources. Only one process should execute its critical section at a time to prevent race conditions.

Structure of Critical Section

Entry Section
      ↓
Critical Section
      ↓
Exit Section
      ↓
Remaining Section

Requirements of Critical Section

  • Mutual Exclusion: Only one process can enter the critical section at a time.
  • Progress: If no process is inside the critical section, another waiting process should be allowed to enter.
  • Bounded Waiting: Every waiting process should get a chance to enter the critical section within a limited time.

Memory Partitioning

Memory Partitioning is a memory management technique in which main memory (RAM) is divided into multiple partitions to accommodate different processes.

Types of Memory Partitioning

  • Fixed Partitioning: Memory is divided into fixed-size partitions before execution begins.
    Advantages: Simple and easy to implement.
    Disadvantages: May cause Internal Fragmentation.
  • Dynamic Partitioning: Memory partitions are created dynamically according to the size of the process.
    Advantages: Better memory utilization.
    Disadvantages: May cause External Fragmentation.

Advantages of Memory Partitioning

  • Efficient utilization of memory
  • Supports multiprogramming
  • Allows multiple processes to reside in memory simultaneously

Disadvantages of Memory Partitioning

  • May cause fragmentation
  • Memory allocation and management become more complex

Understanding Deadlocks in Operating Systems

A Deadlock is a situation in an Operating System where two or more processes are permanently blocked because each process is waiting for a resource held by another process. In simple words, each process is waiting for another process to release a resource, so none of them can continue execution.

Example: P1 holds R1 → waits for R2
         P2 holds R2 → waits for R1

Therefore, both processes remain blocked.

Necessary Conditions for Deadlock

A deadlock can occur only when all the following four conditions exist simultaneously:

  • Mutual Exclusion: A resource can be used by only one process at a time. Other processes must wait until the resource is released.
  • Hold and Wait: A process is holding at least one resource and is waiting to acquire another resource held by another process.
  • No Preemption: A resource cannot be forcibly taken away from a process. It can only be released voluntarily by the process after completing its task.
  • Circular Wait: A circular chain of processes exists where each process is waiting for a resource held by the next process.
P1 → P2 → P3 → P1

Thus, all four conditions are necessary for a deadlock to occur.

Dining Philosophers Problem

The Dining Philosophers Problem is a classical synchronization problem used to demonstrate problems related to deadlock and resource sharing. There are five philosophers sitting around a circular table. Between every two philosophers, there is one fork.

Each philosopher performs two activities:

• Thinking      • Eating

To eat, a philosopher needs both forks—the fork on the left and the fork on the right.

              P1
           F1    F2
        P5          P2
        F5          F3
           P4 ── F4 ── P3

Working of Dining Philosophers

  • A philosopher thinks.
  • When hungry, the philosopher tries to pick up the left fork.
  • Then the philosopher tries to pick up the right fork.
  • If both forks are available, the philosopher eats.
  • After eating, both forks are released.

Problem in Dining Philosophers

If all five philosophers pick up one fork at the same time, each philosopher waits for the other fork.

P1 waits for P2
P2 waits for P3
P3 waits for P4
P4 waits for P5
P5 waits for P1

This creates a circular wait, resulting in a deadlock.

Related entries: