Processes and Threads
Processes and Threads
THREADS. PROCESS
STATES
PROCESSES
vs.
THREADS
(Let’s clarify the
differences)
Processes vs. Threads
(seen from an OS perspective)
PROCESSES
A process was previously defined as a running program. They
are often considered synonyms of programs or applications
From an OS perspective, a process is the highest unit of
kernel scheduling. They
◼ Own resources (allocated by the OS) like memory, files (file
handles), sockets, device handles, windows...
◼ Can communicate with each other using Inter Process
Communication (IPC) resources managed by the OS itself.
◼ Commonly DO NOT SHARE Memory (although can share some
specific memory segments)
Each process has a (big) Process Control Block (PCB)
Process-switching can be an expensive operation
Processes vs. Threads
(seen from an OS perspective)
PROCESSES
Processes vs. Threads
(seen from an OS perspective)
PROCESSES AND
THREADS
A THREAD is a source of
instructions that exists within
a process
Processes vs. Threads
(seen from an OS perspective)
THREADS
Often known as lightweight processes.
They exist within processes:
◼ Each process has at least one thread
◼ Threads share the process’s resources, including memory and files.
This has some advantages but some drawbacks too:
◼ Creating a new thread requires fewer resources than creating a new
process.
◼ Thread-switching is less expensive than process-switching
◼ inter-thread communication is efficient and easy (they share memory) but
prone to synchronization errors (remember the concurrent update problem).
Processes vs. Threads
(seen from an OS perspective)
The Kernel of the OS may be aware of the existence of threads (thus providing
thread-related services) or unaware of them (all thread management is the sole
responsibility of the containing process).
Modern OSs provide kernel support for threads.
❑ A process that “wants to run” (but it’s not running) is said to be a READY PROCESS
❑ A process that “has” the processor (its executing its statements) is called a
RUNNING PROCESS.
❑ ...
After the required event occurs, the blocked process is returned to the ready state (it
is said that the process is unblocked, awakened or released)
Processes and process states
BLOCKED