High-Level Understanding of a Process
- A process is an instance of a computer program that is being executed
- A thread is a basic unit of CPU utilization
- A task is a set of instructions allocated to memory
- A thread is what the CPU actually runs
- A process is what gets loaded in memory
- A process will include one or more threads
- This is because threads are what the CPU actually runs (not processes)
- Tasks and processes are used synonymously sometimes
Defining the Structure of a Process
-
The process model is based on two independent concepts:
- Resource grouping
- Execution
Resource Grouping
- In terms of resource grouping, a process is something that groups related resources together
-
Specifically, a process has the foklowing:
- An address space containing program text and data
- Information about open files
- Information about child processes
- And other resources
Execution
- In terms of execution, a process refers to a primary thread of execution
- A thread of execution refers to a set of threads
- A process doesn't perfectly translate to a set of threads, but we can think of it that way for now
-
Specifically, a thread has the following:
- A program counter that keeps track of which instruction to execute next
- A set of registers that hold its current working variables
- A stack that contains the thread execution history
Summarizing Processes and Threads
- A process refers to a program that is being executed
- A child process is a process created by another process (i.e. the parent process)
- A thread is the basic unit to which the operating system allocates processor time
- A thread can execute any code from the process
- Once a process is created by the operating system, a single thread will be initialized within that process
- This initialized thread is called the primary thread
- Each process can create additional threads from any of its threads
Differentiating between Processes and Threads
-
A major difference between a thread and process is:
-
A process runs in a separate memory space
- Compared to other processes
-
A thread runs in a shared memory space
- Compared to other threads of the same process
-
- Essentially, processes are used to group resources together
- On the other hand, threads are the entities scheduled for execution on the CPU
-
For a process, the operating system:
- Allocates memory for its instricutions and data
-
For a thread, the operating system:
- Handles scheduling
- Allocates CPU time
References
- Python Essential Reference
- Python in a Nuteshell
- Lecture Slides about the Modern Process and Thread
- Threads and Concurrency
- Illustrating the Thread Context
- Hyperthreading and Hardware Threads
- Hyperthreading and the Operating System
- Defining the Architecture of Hyperthreading
- Defining a Process and a Thread
- Another Definition of a Process
- Illustrating a Process and Thread
- Difference between Threads, Tasks, and Processes
Next