SlideShare a Scribd company logo
1
Processes and Threads
Chapter 2
2.1 Processes
2.2 Threads
2.3 Interprocess communication
2.4 Classical IPC problems
2.5 Scheduling
2
Processes
The Process Model
• Multiprogramming of four programs
• Conceptual model of 4 independent, sequential processes
• Only one program active at any instant
3
Process Creation
Principal events that cause process creation
1. System initialization
• Execution of a process creation system
1. User request to create a new process
2. Initiation of a batch job
4
Process Termination
Conditions which terminate processes
1. Normal exit (voluntary)
2. Error exit (voluntary)
3. Fatal error (involuntary)
4. Killed by another process (involuntary)
5
Process Hierarchies
• Parent creates a child process, child processes
can create its own process
• Forms a hierarchy
– UNIX calls this a "process group"
• Windows has no concept of process hierarchy
– all processes are created equal
6
Process States (1)
• Possible process states
– running
– blocked
– ready
• Transitions between states shown
7
Process States (2)
• Lowest layer of process-structured OS
– handles interrupts, scheduling
• Above that layer are sequential processes
8
Implementation of Processes (1)
Fields of a process table entry
9
Implementation of Processes (2)
Skeleton of what lowest level of OS does when an
interrupt occurs
10
Threads
The Thread Model (1)
(a) Three processes each with one thread
(b) One process with three threads
11
The Thread Model (2)
• Items shared by all threads in a process
• Items private to each thread
12
The Thread Model (3)
Each thread has its own stack
13
Thread Usage (1)
A word processor with three threads
14
Thread Usage (2)
A multithreaded Web server
15
Thread Usage (3)
• Rough outline of code for previous slide
(a) Dispatcher thread
(b) Worker thread
16
Thread Usage (4)
Three ways to construct a server
17
Implementing Threads in User Space
A user-level threads package
18
Implementing Threads in the Kernel
A threads package managed by the kernel
19
Hybrid Implementations
Multiplexing user-level threads onto kernel-
level threads
20
Scheduler Activations
• Goal – mimic functionality of kernel threads
– gain performance of user space threads
• Avoids unnecessary user/kernel transitions
• Kernel assigns virtual processors to each process
– lets runtime system allocate threads to processors
• Problem:
Fundamental reliance on kernel (lower layer)
calling procedures in user space (higher layer)
21
Pop-Up Threads
• Creation of a new thread when message arrives
(a) before message arrives
(b) after message arrives
22
Making Single-Threaded Code Multithreaded (1)
Conflicts between threads over the use of a global variable
23
Making Single-Threaded Code Multithreaded (2)
Threads can have private global variables
24
Interprocess Communication
Race Conditions
Two processes want to access shared memory at same time
25
Critical Regions (1)
Four conditions to provide mutual exclusion
1. No two processes simultaneously in critical region
2. No assumptions made about speeds or numbers of CPUs
3. No process running outside its critical region may block
another process
4. No process must wait forever to enter its critical region
26
Critical Regions (2)
Mutual exclusion using critical regions
27
Mutual Exclusion with Busy Waiting (1)
Proposed solution to critical region problem
(a) Process 0. (b) Process 1.
28
Mutual Exclusion with Busy Waiting (2)
Peterson's solution for achieving mutual exclusion
29
Mutual Exclusion with Busy Waiting (3)
Entering and leaving a critical region using the
TSL instruction
30
Sleep and Wakeup
Producer-consumer problem with fatal race condition
31
Semaphores
The producer-consumer problem using semaphores
32
Mutexes
Implementation of mutex_lock and mutex_unlock
33
Monitors (1)
Example of a monitor
34
Monitors (2)
• Outline of producer-consumer problem with monitors
– only one monitor procedure active at one time
– buffer has N slots
35
Monitors (3)
Solution to producer-consumer problem in Java (part 1)
36
Monitors (4)
Solution to producer-consumer problem in Java (part 2)
37
Message Passing
The producer-consumer problem with N messages
38
Barriers
• Use of a barrier
– processes approaching a barrier
– all processes but one blocked at barrier
– last process arrives, all are let through
39
Dining Philosophers (1)
• Philosophers eat/think
• Eating needs 2 forks
• Pick one fork at a time
• How to prevent deadlock
40
Dining Philosophers (2)
A nonsolution to the dining philosophers problem
41
Dining Philosophers (3)
Solution to dining philosophers problem (part 1)
42
Dining Philosophers (4)
Solution to dining philosophers problem (part 2)
43
The Readers and Writers Problem
A solution to the readers and writers problem
44
The Sleeping Barber Problem (1)
45
The Sleeping Barber Problem (2)
Solution to sleeping barber problem.
46
Scheduling
Introduction to Scheduling (1)
• Bursts of CPU usage alternate with periods of I/O wait
– a CPU-bound process
– an I/O bound process
47
Introduction to Scheduling (2)
Scheduling Algorithm Goals
48
Scheduling in Batch Systems (1)
An example of shortest job first scheduling
49
Scheduling in Batch Systems (2)
Three level scheduling
50
Scheduling in Interactive Systems (1)
• Round Robin Scheduling
– list of runnable processes
– list of runnable processes after B uses up its quantum
51
Scheduling in Interactive Systems (2)
A scheduling algorithm with four priority classes
52
Scheduling in Real-Time Systems
Schedulable real-time system
• Given
– m periodic events
– event i occurs within period Pi and requires Ci
seconds
• Then the load can only be handled if
1
1
m
i
i i
C
P



53
Policy versus Mechanism
• Separate what is allowed to be done with
how it is done
– a process knows which of its children threads
are important and need priority
• Scheduling algorithm parameterized
– mechanism in the kernel
• Parameters filled in by user processes
– policy set by user process
54
Thread Scheduling (1)
Possible scheduling of user-level threads
• 50-msec process quantum
• threads run 5 msec/CPU burst
55
Thread Scheduling (2)
Possible scheduling of kernel-level threads
• 50-msec process quantum
• threads run 5 msec/CPU burst

More Related Content

Similar to procress and threads.ppt (20)

PPTX
Lecture 2 Processes in operating systems.pptx
HarrisChikunya
 
PDF
The Thread Chapter 4 of Operating System
mohammadhaidarayoobi
 
PPTX
Operating Systems
Harshith Meela
 
PPT
chapter4-processes nd processors in DS.ppt
aakarshsiwani1
 
PPT
Ipc ppt
Ruchi Sharma
 
PDF
Threads lecture slides for operating systems
amirtarek401
 
PDF
Unit 2 part 2(Process)
WajeehaBaig
 
PPT
Intro Basic of OS .ppt
Varsha506533
 
PPTX
OS_module2. .pptx
hariprasad279825
 
PPTX
CS345 09 - Ch04 Threads operating system1.pptx
RichaAgnihotri13
 
PDF
Operating system 2 by adi
Prof. Dr. K. Adisesha
 
PPTX
THREADS IN OPERATING SYSTEM & multitasking
civilianbro02
 
PDF
Operating System-2 by Adi.pdf
Prof. Dr. K. Adisesha
 
PPTX
Chapter 4 - Operating Systems Threads.pptx
MujtabaVlogs
 
PPTX
Operating Systems R20 Unit 2.pptx
Prudhvi668506
 
PDF
Operating System-2_Process Managementby_Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
CS9222 ADVANCED OPERATING SYSTEMS
Kathirvel Ayyaswamy
 
PPTX
OS Module-2.pptx
bleh23
 
PPTX
Chapter -2 operating system presentation
chnrketan
 
PPTX
2Chapter Two- Process Management(2) (1).pptx
jamsibro140
 
Lecture 2 Processes in operating systems.pptx
HarrisChikunya
 
The Thread Chapter 4 of Operating System
mohammadhaidarayoobi
 
Operating Systems
Harshith Meela
 
chapter4-processes nd processors in DS.ppt
aakarshsiwani1
 
Ipc ppt
Ruchi Sharma
 
Threads lecture slides for operating systems
amirtarek401
 
Unit 2 part 2(Process)
WajeehaBaig
 
Intro Basic of OS .ppt
Varsha506533
 
OS_module2. .pptx
hariprasad279825
 
CS345 09 - Ch04 Threads operating system1.pptx
RichaAgnihotri13
 
Operating system 2 by adi
Prof. Dr. K. Adisesha
 
THREADS IN OPERATING SYSTEM & multitasking
civilianbro02
 
Operating System-2 by Adi.pdf
Prof. Dr. K. Adisesha
 
Chapter 4 - Operating Systems Threads.pptx
MujtabaVlogs
 
Operating Systems R20 Unit 2.pptx
Prudhvi668506
 
Operating System-2_Process Managementby_Adi.pdf
Prof. Dr. K. Adisesha
 
CS9222 ADVANCED OPERATING SYSTEMS
Kathirvel Ayyaswamy
 
OS Module-2.pptx
bleh23
 
Chapter -2 operating system presentation
chnrketan
 
2Chapter Two- Process Management(2) (1).pptx
jamsibro140
 

More from DrBashirMSaad (14)

PDF
googlechromedevelopertools-120424180007-phpapp01.pdf
DrBashirMSaad
 
PDF
Pico-R3-A4 Pinout for ARM embedded system
DrBashirMSaad
 
PDF
Arabic Fonts character foreigners for learner
DrBashirMSaad
 
PPT
DS basics functions.ppt
DrBashirMSaad
 
PPTX
Algorithm analysis.pptx
DrBashirMSaad
 
PDF
Searching Informed Search.pdf
DrBashirMSaad
 
PPTX
2.02.Data_structures_and_algorithms (1).pptx
DrBashirMSaad
 
PDF
1b-150720094704-lva1-app6892.pdf
DrBashirMSaad
 
PPT
01_intro-cpp.ppt
DrBashirMSaad
 
PPT
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
PPT
lec06-programming.ppt
DrBashirMSaad
 
PPT
CS351-L1.ppt
DrBashirMSaad
 
PPT
Matlab_Simulink_Tutorial.ppt
DrBashirMSaad
 
PDF
002 AWSSlides.pdf
DrBashirMSaad
 
googlechromedevelopertools-120424180007-phpapp01.pdf
DrBashirMSaad
 
Pico-R3-A4 Pinout for ARM embedded system
DrBashirMSaad
 
Arabic Fonts character foreigners for learner
DrBashirMSaad
 
DS basics functions.ppt
DrBashirMSaad
 
Algorithm analysis.pptx
DrBashirMSaad
 
Searching Informed Search.pdf
DrBashirMSaad
 
2.02.Data_structures_and_algorithms (1).pptx
DrBashirMSaad
 
1b-150720094704-lva1-app6892.pdf
DrBashirMSaad
 
01_intro-cpp.ppt
DrBashirMSaad
 
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
lec06-programming.ppt
DrBashirMSaad
 
CS351-L1.ppt
DrBashirMSaad
 
Matlab_Simulink_Tutorial.ppt
DrBashirMSaad
 
002 AWSSlides.pdf
DrBashirMSaad
 
Ad

Recently uploaded (20)

PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Ad

procress and threads.ppt