0% found this document useful (0 votes)
7 views16 pages

Process and Threads Overview

Chapter Two discusses processes and threads, defining a process as a program in execution with various states including new, ready, running, waiting, and terminated. It categorizes threads into user-level, kernel-level, and hybrid types, and outlines thread models such as many-to-one, one-to-one, and many-to-many. Additionally, it covers thread usage for responsive UIs, parallel processing, and inter-process communication techniques like pipes, message queues, and shared memory.

Uploaded by

zeezeleke25
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)
7 views16 pages

Process and Threads Overview

Chapter Two discusses processes and threads, defining a process as a program in execution with various states including new, ready, running, waiting, and terminated. It categorizes threads into user-level, kernel-level, and hybrid types, and outlines thread models such as many-to-one, one-to-one, and many-to-many. Additionally, it covers thread usage for responsive UIs, parallel processing, and inter-process communication techniques like pipes, message queues, and shared memory.

Uploaded by

zeezeleke25
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

CHAPTER TWO

PROCESS AND THREADS

1
PROCESS AND THREAD
Process
 Program in execution

Process states
 New

 When a program created

 Ready

 Fully prepared to execute

2
CONT’D
Process states
 Running

 being executed by the CPU


 Waiting

 Process is suspended for an event or resource such as I/O completion.

 Terminated

 Process has completed its execution

3
CONT’D
Thread
 Smallest unit of execution within a process

Types of Thread
Threads are categorized according to who is responsible for their management and scheduling:
 User Level Thread

 Threads are managed by a user-level thread library and are invisible to the OS

4
CONT’D
Thread
 Smallest unit of execution within a process

Types of Thread
Threads are categorized according to who is responsible for their management and scheduling:
 Kernel Level Thread

 Every threads that are created, managed, and scheduled directly by the operating system
(kernel)
 Hybrid Thread

 A combination of user-level and kernel-level threads

5
CONT’D
Thread Models
Describes how user-level threads map to kernel-level threads
 Many-to-One Model

 Multiple user-level threads are mapped to a single kernel

 One-to-One Model

 Each user-level thread maps to a unique kernel thread

 Many-to-Many Model

 Multiple user-level threads map to multiple kernel threads

6
CONT’D
Thread Usage
We can use threads for the following purposes:
 Keeping User Interfaces Responsive

 one thread can handle user input while another loads data

 ,preventing the application from freezing

 Parallel Processing

 Threads let programs to divide large tasks into smaller parts that can run simultaneously
on multiple CPU cores
 Speeding up processing

7
CONT’D
Thread Usage
We can use threads for the following purposes:
 Handling Multiple Requests

 Servers create threads to handle many client connections simultaneously

 allowing them to serve multiple users without delays

 Background Tasks

 like downloading files without interrupting the main program flow

8
CONT’D
Thread Implementation
The following are common activities on thread:
 Thread Creation

 Threads can be created using system APIs using CreateThread() function or

 language-specific libraries like pthreads in C and Thread class

9
CONT’D

Thread Implementation
The following are common activities on thread:
 Thread Synchronization

 threads share resources, synchronization mechanisms like


 locks,

 semaphores,and

 mutexes(mutual exclusion) should be used to prevent conflicts and ensure data consistency.

10
CONT’D
Thread Implementation
The following are common activities on thread:
 Thread Scheduling

 The operating system scheduler allocates CPU time to threads based on

 their priority, enabling multitasking and efficient processor utilization.

 Thread Termination

 Threads can either be stopped before they complete their intended work or

 they can finish and terminate normally after completing their task

11
INTER-PROCESS COMMUNICATION

Allow different processes to communicate and exchange data with each other. The following
techniques implement inter process communication:
 Pipes

 Allows one-way communication between processes(write and read end)

 Message Queues

 Stores messages sent by one process until another process retrieves them.

 Allows asynchronous communication by ensuring messages are received in FIFO order

12
INTER-PROCESS COMMUNICATION

Allow different processes to communicate and exchange data with each other. The following
techniques implement inter process communication:
 Shared Memory

 Multiple processes can access the same memory region to exchange data

 processes can directly read from and write to memory without kernel intervention for each
operation.

13
CONT’D

Allow different processes to communicate and exchange data with each other. The following
techniques implement inter process communication:
 Semaphores

 Used to control access to shared resources by multiple processes

 helps in preventing race conditions when processes share memory or other resources.

14
CONT’D

Allow different processes to communicate and exchange data with each other. The following
techniques implement inter process communication:
 Sockets

 Providing a bidirectional communication channel

 sockets enable processes to interact with one another over a network


 Signals

 Used to notify a process that a particular event has occurred

15
~~~~~END OF CHAPTER 2 ~~~~~

You might also like