0% found this document useful (0 votes)
61 views13 pages

Processes and Threads

A process is the highest unit of kernel scheduling and owns resources like memory and files. A thread exists within a process and shares the process's resources, making thread creation and switching more efficient than processes. Modern operating systems provide kernel support for threads. A ready process is waiting to run, a running process currently has the processor, and a blocked process is waiting for an external event before becoming ready again. The scheduler decides which ready process runs and performs context switching between running processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views13 pages

Processes and Threads

A process is the highest unit of kernel scheduling and owns resources like memory and files. A thread exists within a process and shares the process's resources, making thread creation and switching more efficient than processes. Modern operating systems provide kernel support for threads. A ready process is waiting to run, a running process currently has the processor, and a blocked process is waiting for an external event before becoming ready again. The scheduler decides which ready process runs and performs context switching between running processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PROCESSES AND

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.

Without kernel support With kernel support


(User-level threads) (Kernel-level threads)
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.

Without kernel support With kernel support


(User-level threads) (Kernel-level threads)
PROCESS STATES
(some more concepts and
some more terminology)
Processes and process states
(Ready and running processes)
Usually a set of processes have to
share a single processor or a limited
number of processors. Typically there
will be more processes than
processors

❑ 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.

In a system with a single processor, there may be an arbitrary number of ready


processes but just one running process.
Processes and process states
At the Operating System level, there is a program known as the
SCHEDULER which is responsible for :
 Deciding which of the ready processes should be run

 Performing the context switching, replacing the running


process with the selected ready process and changing the state
of the running process to ready.
The interleaving is “implemented” by the
scheduler.

No assumptions will be made


regarding the behaviour of the
scheduler other than it interleaves
atomic statements arbitrarily.
Processes and process states
(Blocked processes)

A process can be in a state different from ready and running.

A process is said to be in a blocked state when it is neither running nor


ready but waiting for some –external- event to occur. This event may be:
❑ The passing of a certain amount of time
❑ The completion of requested I/O operation

❑ The achievement of a certain condition

❑ A signal from another 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

INACTIVE READY RUNNING COMPLETED

BLOCKED

Initially, a process is INACTIVE. At some point it is activated and becomes


READY. When a concurrent program begins executing, one process is
RUNNING and the others are READY. While executing, it may encounter a
situation that requires the process to cease execution and to become
BLOCKED until it is unblocked and returns to the READY state. When a
process executes it final statement it becomes COMPLETED.

You might also like