Fundamentals 12 min read

Understanding Processes, Threads, and Concurrency: A Practical Guide

This article explains the concepts of processes and threads, their differences, interactions, state transitions, concurrency models, synchronous vs asynchronous execution, and the use of process pools to improve resource management and performance.

Open Source Linux
Open Source Linux
Open Source Linux
Understanding Processes, Threads, and Concurrency: A Practical Guide

1. Process and Thread

1. Process

What is a process?

Code we write is called a program; when the program runs, it becomes a process.

Running a program creates a process that occupies memory and system resources.

Key point

Process is a memory allocation unit, the smallest resource‑management unit.

Process is a container for threads.

Difference between program and process

Program is a static collection of data and instructions; it can be stored for a long time.

Process is the dynamic execution of a program, has a lifecycle and disappears when the program ends.

Process interaction

Processes communicate via TCP/IP ports.

2. Thread

What is a thread?

Thread is the smallest unit the operating system can schedule for execution.

It resides inside a process and is the actual execution unit of that process.

A thread is a single sequential control flow; a process may contain multiple concurrent threads.

Key point

A thread is a pipeline of a process, executing the program without additional resource allocation; it is the smallest execution unit.

Thread interaction

Multiple threads share the same memory space to interact.

3. Relationship between process and thread

Example

Opening a chat application creates a process; opening features such as space, scan, or settings creates threads. Thus a process contains threads, and threads are subsets of a process.

Process is a container for threads

Factory assembly line analogy:

4. Summary

Process : a running application; the smallest unit of resource allocation resource allocation unit.

Thread : the basic unit of CPU time allocation, the smallest execution flow smallest execution unit.

Process allocates a large memory region; a thread only needs a stack.

Every program has at least one process; every process has at least one thread.

Threads can create and terminate other threads; multiple threads in the same process can run concurrently.

2. Parallel, Concurrent, Serial

Concurrency: multiple tasks appear to run simultaneously; a form of pseudo‑parallelism.

Implemented on a single core using time‑slicing.

Parallel: multiple tasks truly run at the same time.

Parallel requires multiple cores; otherwise only concurrency (pseudo‑parallel) is possible.

Serial: one program runs to completion before the next starts.

3. Three States of a Task

During execution, a process cycles through three states: Ready, Running, Blocked.

Ready

After all resources except the CPU are allocated, the process waits for CPU time to become runnable.

Multiple ready processes are placed in a ready queue.

Running

The process has CPU permission and is executing.

On a single‑core system only one process runs; on multi‑core systems several can run simultaneously.

Blocked (sleep)

If a running process must wait for an event (I/O, higher‑priority task), the OS removes its CPU time, putting it into the blocked state.

Typical causes: I/O wait, preemption by higher‑priority tasks, etc.

State transitions

A process may move repeatedly among these states; the diagram below illustrates the transitions.

Ready → Running

The scheduler assigns a CPU time slice, moving the process to the running state.

Running → Ready

When the time slice expires, the process returns to the ready queue.

Running → Blocked

If the process waits for I/O or is preempted, it becomes blocked.

Blocked → Ready

Once the awaited event completes, the process becomes ready again.

4. Two Ways to Submit Tasks

Synchronous

The sender waits for a response before sending the next message.

Two programs are interdependent; one thread blocks until the other finishes.

Asynchronous

The sender does not wait for a response before sending the next message.

Threads operate independently of each other.

Examples

Synchronous

Calling someone to eat: you wait for acknowledgment before going together.

A phone call is synchronous; both parties talk at the same time.

Asynchronous

You are told to eat, but you may go immediately or later after receiving the message.

Sending a message is asynchronous; you can message another person without waiting.

5. Process Pool

What is a process pool?

A technique composed of resource processes and manager processes.

Why use a process pool?

During peak load thousands of tasks may need execution. Creating and destroying a process for each task is costly, and the OS cannot run all simultaneously. A pool reuses a fixed number of pre‑created processes, reducing overhead and achieving concurrency.

Concept

Define a pool with a fixed number of processes; tasks borrow a process from the pool.

After completing, the process returns to the pool for future tasks.

If tasks exceed the pool size, they wait for a free process.

The fixed pool size limits concurrent processes, providing controlled concurrency.

Resource process

Pre‑created idle processes; the manager assigns work to them.

Manager process

Creates resource processes, distributes work, and recycles completed processes.

Interaction

The manager communicates with resource processes via IPC mechanisms such as signals, semaphores, message queues, and pipes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

concurrencyThreadOperating SystemprocessProcess Pool
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.