2. PROCESS MANAGEMENT

2.1. The Process Model

Process Model (Simplified) 

What is a Process Model?

  • A process model is a general description of how similar types of processes behave.

  • It serves as a template used to create specific processes during development.

 Uses of Process Models:

  1. Descriptive – Shows what actually happens during a process.

  2. Prescriptive – Explains how a process should be done (rules/guidelines).

  3. Explanatory – Gives reasons behind process steps and helps analyze choices.

 Process Levels:

  • Organized in a hierarchy (top to bottom).

  • Each level should have clear details (e.g., who performs each step).


Threads (Simplified)

What is a Thread?

  • A thread is a small unit of a process that can run independently.

  • Think of it as a lightweight process.

  • Multiple threads can exist within a single process, sharing memory and resources.

Why Use Threads?

  • Faster and more efficient than creating new processes.

  • Great for parallel tasks (e.g., web servers, background tasks).

  • Require fewer system resources.


🔄 Process vs Thread

Feature Process Thread
Independence Independent Share resources with others
Memory Separate memory space Shared memory
Creation Costly Cheap
Communication Needs interprocess communication. Easy, direct sharing

Types of Threads

1. User-Level Threads

  • Managed in user space (not visible to OS).

  • Faster, no kernel calls.

  • Limitation: If one thread blocks, all do.

2. Kernel-Level Threads

  • Managed by the OS kernel.

  • Slower, but better for blocking operations.

  • Allows true parallel execution on multiple CPUs.


Multithreading Models

1. Many-to-One

  • Many user threads map to one kernel thread.

  • No parallelism.

  • One blocked thread blocks all.

2. One-to-One

  • Each user thread has a kernel thread.

  • True parallelism, but high overhead.

  • Used in Windows NT/2000.

3. Many-to-Many

  • Many user threads map to many kernel threads.

  • Best of both worlds – flexibility and performance.

  • Used in Solaris.


Context Switching

What is it?

  • Switching the CPU from one process/thread to another.

Steps:

  1. Save the current process’s register values.

  2. Load the next process’s register values.

  3. OS scheduler decides who runs next.


Advantages of Threads

  • Faster context switching

  • Shared memory = easier communication

  • Ideal for apps needing parallel tasks (e.g., game engines, servers)

Disadvantages of Threads

  • No protection between threads

  • Security issues

  • Blocking system calls can affect all threads (if not properly managed)