lecture 2: Process and Thread Management
2.1 Process 2.1 Thread • defination Threads • Types
• defination process • process model of Threads • Thread Lifecycle
• Process Hierarchies
• Process States and Transitions
• Thread Operations
• Process Termination
• Multithreading
defination process
Definition: A process is a program in execution. j
A real example of a process in execution could be when you open a webbrowser,such as
Google Chrome, on your computer. Here's how it works:
Program: Google Chrome is a program stored on your computer.
Execution: When you launch Google Chrome, the operating systemloads theprogram into
memory and starts its execution. This running instance of Chromeisaprocess.
Process in Execution: While you're using Google Chrome to browse theweb, it’sactively
running as a process. Each tab you open in Chrome might alsobetreatedas a separate
process (especially in modern browsers), and all of theseprocessesare using CPU time,
memory, and other resources.
Resource Allocation: The operating system manages resources, like memory(RAM),CPU
time, and access to I/O devices, for each process, ensuring that Chromefunctions
smoothly while you browse.
process model
A process model how processes are created, scheduled, executed, and
how
they use system resources like CPU, memory, andI/Odevices.�Key Functions:
Controls process life cycle (start →run →wait →finish) Manages
CPU time and memory
Allows multiple processes to work smoothly together
Types of Process Models
Type Description Example
1. Single Only one process run time. MS-DOS,
Model Tasking oldmobileOS
No multitasking.
Multitasking Multiple processesrunsame time Windows, macOS, Linux a
Model quickly switchingbetween them.
the
Multithreadi A single process hasmultiplethrea Web browsers
ngModel each doing a separatetask.
downloads)
Multiprocessi System has multiple CPUs/coresto Modern PCs, servers
ngModel processes inparallel.
Distribute Model Processes Cloud apps likeGoo
arespread acrossmultiple
computersconnectedby a network Docs
Process Hierarchies
Process Hierarchies refer to the organization of processes in an operatingsystem,where
each process may spawn child processes, forming a tree-like structure.
❑System Process (Parent): When Windows starts, the system's coreprocesses, such as the
System Idle Process and Windows Session Manager (smss.exe), areamong the first to be
initialized by the Kernel.
❑Parent Process: Once the system is up and running, processes
likeexplorer.exe(which handles the Windows graphical interface) are launched.
explorer.exeserves as the parent for many user-level applications.
❑Child Processes: When you open an application (e.g., Mxicrosoft Word,
GoogleChrome), explorer.exe will spawn the respective processes.
❑Grandchild Processes: Within applications, additional
processesmaybe spawned for specific tasks. For example:
Google Chrome might create several child processes for different tabs, extensions,
or background services.
Microsoft Word could launch background processes for
spell-checkingorauto-saving.
❑Process Termination: When an application is closed, its childprocesses
are terminated as well. If an application is forcefullyclosed(e.g., through
Task Manager), its child processes will alsobeterminated.
Process State andTransition
Process State
A process state defines the current status of a process during its executionintheoperating
system. A process moves through different states based on systemresources,CPU scheduling,
and I/O operations.
The common process states are:
❑New (Create) – The process is created but not yet ready to execute. ❑Ready – The
process is waiting for CPU allocation.
❑Running – The process is currently executing on the CPU. ❑Blocked (Waiting) – The process
is waiting for an I/O operation or another event.
❑Suspended (Ready Suspended / Blocked Suspended) – The process is
temporarilymoved to secondary storage to free up memory.
❑Terminated – The process has finished execution and is removed fromthesystem.
Process Transition
A process transition is the movement of a process
fromonestatetoanother due to scheduling decisions, I/O operations, or
systemconstraints.
Common Process Transitions
Transition Description Example
Create → A new process is created and placed in Ready the
ready queue. Launching an application.
Ready → The CPU selects a process from Running the ready queue
for execution. A game starts running after youclick"Play".
Running → The process needs I/O (e.g., waiting for user Blo A program waiting for a fil
input, disk read/write).
Blocked →The I/O operation completes, and the Ready A downloaded file is nowre
moves to ready. process
processing.
Running →(Preemption) The CPU is taken away from the pr An antivirus scan interrupts a backg
Ready to
a higher-priority task. task.
Ready → The process is moved to secondary storage Rea to
Suspended A minimized application is paus
free memory.
Blocked →Suspended The blocked process is moved to seco A large file download is paused.
Blocked
storage due to memory constraints.
Blocked SuspendedBlocked The process is moved back to memory Resuming a paused file download.
→
waiting for I/O.
Ready Suspended The process is brought back to memory → Rea and is
ready to run. Opening a minimized applicationagain.
Running → Terminated The process completes executi exits. Closing an application after use
Process Termination
Process termination refers to the action of stopping or ending a runningprocessina
computer system. Here are the main ways a process can be terminatedinclude:
❑Normal Termination: The process finishes its task successfully andterminatesitself.
This often occurs when the process has completed its
designatedtaskorencountered an end condition.
❑Forced Termination: When a process becomes unresponsive or behavesincorrectly,
it can be forcibly terminated using various systemcommandsortools.Examples
include using kill command in Unix/Linux or Task Manager inWindowsto end a
process.
❑Abnormal Termination: A process may end unexpectedly due to errors orcrashes. These
errors could be in the software, systemresource limitations, orhardware failures.
defination Threads
A thread is the smallest unit of execution in a process.
Aprocesscanhave multiple threads running at the same time,
sharingresourcesbut
executing different tasks independently.
Example:
Imagine a web browser:
✔One thread loads a webpage. jhjhj
✔Another thread downloads a file.
✔Another thread runs JavaScript in the background.
Types of Threads
a) User-Level Threads
Managed by applications, not the OS.
Faster and more efficient but cannot run multiple threads inparallel
onmulti-core CPUs.
Example:
✔A Java program with multiple threads running inside theJVM. b)
Kernel-Level Threads
Managed by the operating system.
Can take full advantage of multi-core processors. Example:
✔Linux processes using multiple threads to execute different tasksconcurrently.
Thread Lifecycle
A thread passes through different states during execution: ❑New –
Thread is created but not started.
❑Runnable – Ready to run, waiting for CPU time. ❑Running – The thread
is actively executing. ❑Blocked – Waiting for a resource (e.g., file access).
❑Terminated – Thread has completed execution or was stopped.
Thread Operations
a) Thread Creation
Thread Creation is the process of starting a new thread within a program.
Example: In Microsoft Word, when you type text a separate thread handles
auto-savingwithout interrupting your work.
b) Thread Synchronization
Ensures multiple threads don’t interfere with each other. Uses Locks, Semaphores, and
Mutexes to control access to shared resources.
Example:A banking app where multiple users are withdrawing money
fromthesameaccount. Synchronization ensures the balance is updated correctly.
c) Thread Scheduling
The OS decides which thread runs next.
Uses Preemptive Scheduling (OS decides) or Cooperative Scheduling (Threadsyieldcontrol)
Multithreading
Multithreading allows a program to run multiple threads simultaneously,
improving performance.
Advantages of Multithreading:
✔ Faster execution
✔ Efficient CPU utilization
✔ Better system responsiveness Disadvantages:
❌ More complex programming
❌ Risk of deadlocks and race conditions