Basic Concepts

Basic Concepts of Processes and Threads

Process

Definition: A process is one execution of a program on a computer; it is the basic unit for resource allocation and scheduling in the system.

Characteristics:

  1. Dynamism: a process is the execution of a program and therefore has a life cycle
  2. Concurrency: many processes can exist and run at the same time
  3. Independence: a process is an independent unit of resource allocation
  4. Structure: a process consists of a program, its data, and a process control block

Composition of a process:

  • Program segment: holds the program code
  • Data segment: holds the data the program works on while running
  • Process Control Block (PCB): holds the management information for the process

Process Control Block (PCB)

Role of the PCB: the PCB is the core data structure through which the operating system manages a process; it contains all of the management information for that process.

Main contents of the PCB:

  1. Process identification information:

    • Process ID (PID)
    • Parent process ID (PPID)
    • User ID (UID)
  2. Processor state information:

    • Contents of the general-purpose registers
    • Program counter (PC)
    • Program status word (PSW)
    • Stack pointer
  3. Process scheduling information:

    • Process state
    • Process priority
    • Scheduling queue pointers
    • Other scheduling parameters
  4. Process control information:

    • Program and data addresses
    • Synchronization and communication mechanisms of the process
    • Resource inventory
    • Link pointers

Thread

Definition: A thread is an execution unit inside a process; it is the basic unit the CPU schedules.

Characteristics:

  1. Lightweight: creating, terminating, and switching threads is cheap
  2. Sharing: threads of the same process share the process’s resources
  3. Concurrency: many threads can execute concurrently
  4. Independence: every thread has its own program counter and stack

Relationship between threads and processes:

Process
Code segment (shared)Data segment (shared)File descriptors (shared)
Thread 1Program counterRegister setStack
Thread 2Program counterRegister setStack
…

Differences Between Processes and Threads

AspectProcessThread
Resource allocationOwn address spaceShares the process’s address space
Creation overheadHigh (memory must be allocated)Low (existing resources are reused)
Switching overheadHigh (the address space must be switched)Low (only the registers are switched)
CommunicationInter-process communication (IPC)Shared memory, global variables
ConcurrencyProcess-level concurrencyThread-level concurrency
IndependenceFully independentRelatively independent

Multithreading Models

1. User-Level Threads (ULT)

Characteristics:

  • Thread management is performed by the user program
  • The operating system does not know that the threads exist
  • Switching threads does not require the kernel

Advantages:

  • Low thread-switching overhead
  • Flexible scheduling algorithms
  • Good portability

Disadvantages:

  • One blocked thread stalls the whole process
  • Multi-core CPUs cannot be exploited

2. Kernel-Level Threads (KLT)

Characteristics:

  • Thread management is performed by the operating system kernel
  • The kernel allocates resources for every thread
  • Switching threads requires the kernel

Advantages:

  • Multi-core CPUs can be fully exploited
  • One blocked thread does not affect the other threads
  • Fairer scheduling

Disadvantages:

  • High thread-switching overhead
  • Heavy consumption of system resources

3. Hybrid Model

Characteristics:

  • Combines the advantages of user-level and kernel-level threads
  • User-level threads are mapped onto kernel-level threads
  • Offers better performance and flexibility

Implementation options:

  • Many-to-many model: several user threads are mapped onto several kernel threads
  • One-to-one model: each user thread corresponds to one kernel thread
  • Many-to-one model: several user threads are mapped onto a single kernel thread

Process States

Basic States

  1. Ready state:

    • The process has obtained every resource except the CPU
    • It is waiting for the CPU to schedule it
    • It is queued in the ready queue
  2. Running state:

    • The process is executing on the CPU
    • It occupies the CPU
    • Only one process can be in the running state at any moment
  3. Blocked state:

    • The process is waiting for an event or a resource
    • It cannot be scheduled by the CPU
    • It waits in the blocked queue

State Transitions

ReadyReady
DispatchTime slice expired
RunningRunning
Wait for event
BlockedBlocked
Event complete → ready again

Transition conditions:

  • Ready → Running: the CPU scheduler selects the process for execution
  • Running → Ready: the time slice expires, or a higher-priority process preempts it
  • Running → Blocked: the process requests I/O or waits for a resource
  • Blocked → Ready: the awaited event occurs, or the resource becomes available

Process Control

Process Creation

Ways a process is created:

  1. System initialization: the system creates system processes at boot time
  2. User request: a user creates a process through a command or a program
  3. Process derivation: an existing process creates a child process

Creation procedure:

  1. Allocate a PCB
  2. Allocate the memory space
  3. Initialize the PCB
  4. Place the process in the ready queue

Process Termination

Ways a process terminates:

  1. Normal termination: the process finishes its execution
  2. Abnormal termination: the process fails while running
  3. External intervention: it is killed by another process or by a user

Termination procedure:

  1. Release the resources held by the process
  2. Release the PCB
  3. Notify the parent process

Process Switching

When a switch happens:

  • The time slice expires
  • A higher-priority process becomes ready
  • The running process blocks
  • The running process terminates

Switching procedure:

  1. Save the context of the current process
  2. Update the PCB information
  3. Select the next process to run
  4. Restore the context of the new process
  5. Jump to the new process

Glossary

TermAbbreviationExplanation
Process-One execution of a program
Thread-An execution unit inside a process
Process Control BlockPCBThe data structure that stores information about a process
Process State-The current state of a process
Ready State-The state of waiting to be scheduled onto the CPU
Running State-The state of executing on the CPU
Blocked State-The state of waiting for an event
New State-The state of being created
Terminated State-The state of having finished execution
Process Creation-Creating a new process
Process Termination-Terminating a process
Process Blocking-A process entering the blocked state
Process Wakeup-A process moving from the blocked state to the ready state
Context Switch-Switching the execution environment from one process to another
Process Context-The environment information of a process’s execution
User-Level ThreadULTA thread managed in user space
Kernel-Level ThreadKLTA thread managed by the kernel
Lightweight ProcessLWPA user thread supported by the kernel
Process Scheduling-Choosing which process executes
Job Scheduling-Choosing which jobs enter memory
Medium-Term Scheduling-Swapping processes into and out of memory
Primitive-An operation that cannot be interrupted

Found an issue with this content?

Tell us what could be improved.