This post is a part of my study on system performance and troubleshooting. I’ve recently been bitten (again) by the performance bug. Having always been interested in keeping applications performant I have looked out for improvements where possible, but usually business deadlines overruled my desire to dive into the weeds of performance. I’ve decided to remedy this and publish whatever I come across that might help others speed up their search too.
What is a Process?
A process is a program that runs on the CPU in user mode. It must utilize system calls to request resources from the kernel [1]. Each process has data within it’s own memory address space and metadata within the kernel (ie. a process id). It has its own registers, file descriptors, and thread stacks.
What is a Thread?
A thread is the smallest sequence of programmed instructions that can be managed independently by the OS’s scheduler. Threads exist within a process and share the process’s resources, including memory and open files.
Here’s a diagram to illustrate the difference between a process and threads.
+--------------------------------------+
| Process |
| +----------------------------------+ |
| | Thread 1 | |
| | - Executes specific instructions | |
| | - Shares process resources | |
| +----------------------------------+ |
| +----------------------------------+ |
| | Thread 2 | |
| | - Executes specific instructions | |
| | - Shares process resources | |
| +----------------------------------+ |
| ... |
| +----------------------------------+ |
| | Thread N | |
| | - Executes specific instructions | |
| | - Shares process resources | |
| +----------------------------------+ |
+--------------------------------------+
These threads are part of the same process and therefore share the process’s resources, but they execute independently.
Each thread can execute its own sequence of programmed instructions, but since they’re part of the same process, they can efficiently share information through shared memory within the process’s address space. This setup allows for efficient concurrent execution within a single process.
What is a Task?
Tasks can be described as a runnable unit of work. It can describe a process or a thread.
Summary
In summary, a process is a more heavyweight, isolated execution environment, while a thread is a lighter, shared execution environment within a process. A task is a more general term and can refer to either a process or a thread, depending on the context. The distinction is important for understanding how operating systems manage computational tasks and how they are scheduled and executed on computer hardware.
Resources
- Gregg, B. (2020). Systems Performance: Enterprise and the Cloud (2nd ed.). Available online.
Leave a Reply