SlideShare a Scribd company logo
1 of 30
PROCESSES & THREADS
PROCESSES AND THREADS
• Processes
• Threads
• Scheduling
• Interprocess communication
• Classical IPC problems
WHAT IS A PROCESS?
• Code, data, and stack
• Usually (but not always) has its own address space
• Program state
• CPU registers
• Program counter (current location in the code)
• Stack pointer
• Only one process can be running in the CPU at any
given time!
3
THE PROCESS MODEL
• Multiprogramming of four
programs
• Conceptual model
• 4 independent processes
• Processes run sequentially
• Only one program active at any
instant!
• That instant can be very short…
4
A
C
D
Single PC
(CPU’s point of view)
A
B
C D
Multiple PCs
(process point of view)
B
B
A
B
C
D
Time
WHEN IS A PROCESS CREATED?
• Processes can be created in two ways
• System initialization: one or more processes created
when the OS starts up
• Execution of a process creation system call: something
explicitly asks for a new process
• System calls can come from
• User request to create a new process (system call
executed from user shell)
• Already running processes
• User programs
• System daemons
5
PROCESS CREATION
• Parent process creates children processes, which, in turn
create other processes, forming a tree of processes.
• Generally, process identified and managed via a process
identifier (pid).
• Resource sharing options
• Parent and children share all resources
• Children share subset of parent’s resources
• Parent and child share no resources
• Execution options
• Parent and children execute concurrently
• Parent waits until children terminate
PROCESS CREATION (CONT.)
• Address space
• Child duplicate of parent
• Child has a program loaded into it
• UNIX examples
• fork() system call creates new process
• exec() system call used after a fork() to replace the
process’ memory space with a new program
WHEN DO PROCESSES END?
• Conditions that terminate processes can be
• Voluntary
• Involuntary
• Voluntary
• Normal exit
• Error exit
• Involuntary
• Fatal error (only sort of involuntary)
• Killed by another process
8
PROCESS TERMINATION
• Process executes last statement and then asks the
operating system to delete it using the exit() system call.
• Returns status data from child to parent (via wait())
• Process’ resources are deallocated by operating
system
• Parent may terminate the execution of children
processes using the abort() system call. Some reasons
for doing so:
• Child has exceeded allocated resources
• Task assigned to child is no longer required
• The parent is exiting and the operating systems does
not allow a child to continue if its parent terminates
PROCESS TERMINATION
• Some operating systems do not allow a child to exist if its parent
has terminated. If a process terminates, then all its children must
also be terminated.
• cascading termination. All children, grandchildren,
etc. are terminated.
• The termination is initiated by the operating system.
• The parent process may wait for termination of a child process by
using the wait()system call. The call returns status information and
the pid of the terminated process
pid = wait(&status);
• If no parent waiting (did not invoke wait()) process is a zombie
• If parent terminated without invoking wait , process is an orphan
PROCESS HIERARCHIES
• Parent creates a child process
• Child processes can create their own children
• Forms a hierarchy
• UNIX calls this a “process group”
• If a process exits, its children are “inherited” by the
exiting process’s parent
• Windows has no concept of process hierarchy
• All processes are created equal
11
PROCESS STATES
• Process in one of 5 states
• Created
• Ready
• Running
• Blocked
• Exit
• Transitions between states
1 - Process enters ready queue
2 - Scheduler picks this process
3 - Scheduler picks a different process
4 - Process waits for event (such as I/O)
5 - Event occurs
6 - Process exits
7 - Process ended by another process
12
Blocked
(waiting)
Created
Exit
Ready
Running
1
5
4
3
2
7
7
6
PROCESSES IN THE OS
• Two “layers” for processes
• Lowest layer of process-structured OS handles interrupts,
scheduling
• Above that layer are sequential processes
• Processes tracked in the process table
• Each process has a process table entry
13
Scheduler
0 1 N-2 N-1
…
Processes
WHAT’S IN A PROCESS TABLE
ENTRY?
14
File management
Root directory
Working (current) directory
File descriptors
User ID
Group ID
Memory management
Pointers to text, data, stack
or
Pointer to page table
Process management
Registers
Program counter
CPU status word
Stack pointer
Process state
Priority / scheduling parameters
Process ID
Parent process ID
Signals
Process start time
Total CPU usage
May be
stored
on stack
WHAT HAPPENS ON A
TRAP/INTERRUPT?
1. Hardware saves program counter (on stack or in a
special register)
2. Hardware loads new PC, identifies interrupt
3. Assembly language routine saves registers
4. Assembly language routine sets up stack
5. Assembly language calls C to run service routine
6. Service routine calls scheduler
7. Scheduler selects a process to run next (might be the
one interrupted…)
8. Assembly language routine loads PC & registers for
the selected process
15
THREADS: “PROCESSES” SHARING MEMORY
• Process == address space
• Thread == program counter / stream of instructions
• Two examples
• Three processes, each with one thread
• One process with three threads
16
Kernel Kernel
Threads
Threads
System
space
User
space
Process 1 Process 2 Process 3 Process 1
PROCESS & THREAD INFORMATION
17
Per process items
Address space
Open files
Child processes
Signals & handlers
Accounting info
Global variables
Per thread items
Program counter
Registers
Stack & stack pointer
State
Per thread items
Program counter
Registers
Stack & stack pointer
State
Per thread items
Program counter
Registers
Stack & stack pointer
State
THREADS & STACKS
18
Kernel
Process
Thread 1 Thread 2 Thread 3
Thread 1’s
stack
Thread 3’s
stack
Thread 2’s
stack
User space
=> Each thread has its own stack!
WHY USE THREADS?
• Allow a single application to
do many things at once
• Simpler programming model
• Less waiting
• Threads are faster to create
or destroy
• No separate address space
• Overlap computation and
I/O
• Could be done without
threads, but it’s harder
• Example: word processor
• Thread to read from keyboard
• Thread to format document 19
Kernel
MULTITHREADED WEB SERVER
20
Kernel
Network
connection
Dispatcher
thread
Worker
thread
Web page
cache
while(TRUE) {
getNextRequest(&buf);
handoffWork(&buf);
}
while(TRUE) {
waitForWork(&buf);
lookForPageInCache(&buf,&page);
if(pageNotInCache(&page)) {
readPageFromDisk(&buf,&page);
}
returnPage(&page);
}
THREE WAYS TO BUILD A SERVER
• Thread model
• Parallelism
• Blocking system calls
• Single-threaded process: slow, but easier to do
• No parallelism
• Blocking system calls
• Finite-state machine
• Each activity has its own state
• States change when system calls complete or interrupts occur
• Parallelism
• Nonblocking system calls
• Interrupts
21
IMPLEMENTING THREADS
22
Kernel
Run-time
system
Thread
table
Process
table
Kernel
Thread
Process
Thread
table
Process
table
User-level threads
+ No need for kernel support
- May be slower than kernel threads
- Harder to do non-blocking I/O
Kernel-level threads
+ More flexible scheduling
+ Non-blocking I/O
- Not portable
PRODUCER-CONSUMER PROBLEM
• Paradigm for cooperating processes, producer
process produces information that is consumed by a
consumer process
BOUNDED-BUFFER – SHARED-
MEMORY SOLUTION
• Shared data
• #define BUFFER_SIZE 10
• typedef struct {
• . . .
• } item;
• item buffer[BUFFER_SIZE];
• int in = 0;
• int out = 0;
• Solution is correct, but can only use BUFFER_SIZE-1
elements
BOUNDED-BUFFER – PRODUCER
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
BOUNDED BUFFER – CONSUMER
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
/* consume the item in next consumed */
}
26
SCHEDULING
• What is scheduling?
• Goals
• Mechanisms
• Scheduling on batch systems
• Scheduling on interactive systems
• Other kinds of scheduling
• Real-time scheduling
27
WHY SCHEDULE PROCESSES?
• Bursts of CPU usage alternate with periods of I/O wait
• Some processes are CPU-bound: they don’t make many I/O
requests
• Other processes are I/O-bound and make many kernel requests
28
CPU bound
I/O bound
CPU bursts I/O waits
Total CPU usage
Total CPU usage
Time
WHEN ARE PROCESSES
SCHEDULED?
• At the time they enter the system
• Common in batch systems
• Two types of batch scheduling
• Submission of a new job causes the scheduler to run
• Scheduling only done when a job voluntarily gives up
the CPU (i.e., while waiting for an I/O request)
• At relatively fixed intervals (clock interrupts)
• Necessary for interactive systems
• May also be used for batch systems
• Scheduling algorithms at each interrupt, and picks the next
process from the pool of “ready” processes
29
Scheduling goals
• All systems
• Fairness: give each process a fair share of the CPU
• Enforcement: ensure that the stated policy is carried out
• Balance: keep all parts of the system busy
• Batch systems
• Throughput: maximize jobs per unit time (hour)
• Turnaround time: minimize time users wait for jobs
• CPU utilization: keep the CPU as busy as possible
• Interactive systems
• Response time: respond quickly to users’ requests
• Proportionality: meet users’ expectations
• Real-time systems
• Meet deadlines: missing deadlines is a system failure!
• Predictability: same type of behavior for each time slice
30

More Related Content

Similar to Processes, Threads.pptx

Processes
ProcessesProcesses
ProcessesRaviRaj339
 
Basic concept of process
Basic concept of processBasic concept of process
Basic concept of processNabin Dahal
 
Unit 2_OS process management
Unit 2_OS process management Unit 2_OS process management
Unit 2_OS process management JayeshGadhave1
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process managementArnav Chowdhury
 
08 operating system support
08 operating system support08 operating system support
08 operating system supportdilip kumar
 
08 operating system support
08 operating system support08 operating system support
08 operating system supportBitta_man
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and terminationVaibhav Khanna
 
08 operating system support
08 operating system support08 operating system support
08 operating system supportSher Shah Merkhel
 
Processes and operating systems
Processes and operating systemsProcesses and operating systems
Processes and operating systemsRAMPRAKASHT1
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxssuser3dfcef
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesHelpWithAssignment.com
 
Process Management.pdf
Process Management.pdfProcess Management.pdf
Process Management.pdfYashjangid9
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationShivam Mitra
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesPeter Tröger
 
How Operating system works.
How Operating system works. How Operating system works.
How Operating system works. Fahad Farooq
 
MK Sistem Operasi.pdf
MK Sistem Operasi.pdfMK Sistem Operasi.pdf
MK Sistem Operasi.pdfwisard1
 

Similar to Processes, Threads.pptx (20)

Processes
ProcessesProcesses
Processes
 
Basic concept of process
Basic concept of processBasic concept of process
Basic concept of process
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
 
Unit 2_OS process management
Unit 2_OS process management Unit 2_OS process management
Unit 2_OS process management
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Thread
ThreadThread
Thread
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and termination
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
Processes and operating systems
Processes and operating systemsProcesses and operating systems
Processes and operating systems
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptx
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
UNIT I-Processes.pptx
UNIT I-Processes.pptxUNIT I-Processes.pptx
UNIT I-Processes.pptx
 
Process Management.pdf
Process Management.pdfProcess Management.pdf
Process Management.pdf
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - Processes
 
How Operating system works.
How Operating system works. How Operating system works.
How Operating system works.
 
MK Sistem Operasi.pdf
MK Sistem Operasi.pdfMK Sistem Operasi.pdf
MK Sistem Operasi.pdf
 
Chap3.ppt
Chap3.pptChap3.ppt
Chap3.ppt
 

More from LECO9

C Programming Intro.ppt
C Programming Intro.pptC Programming Intro.ppt
C Programming Intro.pptLECO9
 
Embedded Systems.pptx
Embedded Systems.pptxEmbedded Systems.pptx
Embedded Systems.pptxLECO9
 
Basic Electronics.pptx
Basic Electronics.pptxBasic Electronics.pptx
Basic Electronics.pptxLECO9
 
Intro to Microcontroller.pptx
Intro to Microcontroller.pptxIntro to Microcontroller.pptx
Intro to Microcontroller.pptxLECO9
 
PIC_Intro.pptx
PIC_Intro.pptxPIC_Intro.pptx
PIC_Intro.pptxLECO9
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxLECO9
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxLECO9
 
UNIONS IN C.pptx
UNIONS IN C.pptxUNIONS IN C.pptx
UNIONS IN C.pptxLECO9
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptxLECO9
 
DATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptxDATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptxLECO9
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxLECO9
 
DESIGN PATTERN.pptx
DESIGN PATTERN.pptxDESIGN PATTERN.pptx
DESIGN PATTERN.pptxLECO9
 
INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxLECO9
 
cprogramming Structures.pptx
cprogramming Structures.pptxcprogramming Structures.pptx
cprogramming Structures.pptxLECO9
 
POINTERS.pptx
POINTERS.pptxPOINTERS.pptx
POINTERS.pptxLECO9
 
DYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptxDYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptxLECO9
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxLECO9
 
cprogramming strings.pptx
cprogramming strings.pptxcprogramming strings.pptx
cprogramming strings.pptxLECO9
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxLECO9
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptxLECO9
 

More from LECO9 (20)

C Programming Intro.ppt
C Programming Intro.pptC Programming Intro.ppt
C Programming Intro.ppt
 
Embedded Systems.pptx
Embedded Systems.pptxEmbedded Systems.pptx
Embedded Systems.pptx
 
Basic Electronics.pptx
Basic Electronics.pptxBasic Electronics.pptx
Basic Electronics.pptx
 
Intro to Microcontroller.pptx
Intro to Microcontroller.pptxIntro to Microcontroller.pptx
Intro to Microcontroller.pptx
 
PIC_Intro.pptx
PIC_Intro.pptxPIC_Intro.pptx
PIC_Intro.pptx
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
UNIONS IN C.pptx
UNIONS IN C.pptxUNIONS IN C.pptx
UNIONS IN C.pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
DATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptxDATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
DESIGN PATTERN.pptx
DESIGN PATTERN.pptxDESIGN PATTERN.pptx
DESIGN PATTERN.pptx
 
INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptx
 
cprogramming Structures.pptx
cprogramming Structures.pptxcprogramming Structures.pptx
cprogramming Structures.pptx
 
POINTERS.pptx
POINTERS.pptxPOINTERS.pptx
POINTERS.pptx
 
DYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptxDYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
cprogramming strings.pptx
cprogramming strings.pptxcprogramming strings.pptx
cprogramming strings.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptx
 

Recently uploaded

power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Processes, Threads.pptx

  • 2. PROCESSES AND THREADS • Processes • Threads • Scheduling • Interprocess communication • Classical IPC problems
  • 3. WHAT IS A PROCESS? • Code, data, and stack • Usually (but not always) has its own address space • Program state • CPU registers • Program counter (current location in the code) • Stack pointer • Only one process can be running in the CPU at any given time! 3
  • 4. THE PROCESS MODEL • Multiprogramming of four programs • Conceptual model • 4 independent processes • Processes run sequentially • Only one program active at any instant! • That instant can be very short… 4 A C D Single PC (CPU’s point of view) A B C D Multiple PCs (process point of view) B B A B C D Time
  • 5. WHEN IS A PROCESS CREATED? • Processes can be created in two ways • System initialization: one or more processes created when the OS starts up • Execution of a process creation system call: something explicitly asks for a new process • System calls can come from • User request to create a new process (system call executed from user shell) • Already running processes • User programs • System daemons 5
  • 6. PROCESS CREATION • Parent process creates children processes, which, in turn create other processes, forming a tree of processes. • Generally, process identified and managed via a process identifier (pid). • Resource sharing options • Parent and children share all resources • Children share subset of parent’s resources • Parent and child share no resources • Execution options • Parent and children execute concurrently • Parent waits until children terminate
  • 7. PROCESS CREATION (CONT.) • Address space • Child duplicate of parent • Child has a program loaded into it • UNIX examples • fork() system call creates new process • exec() system call used after a fork() to replace the process’ memory space with a new program
  • 8. WHEN DO PROCESSES END? • Conditions that terminate processes can be • Voluntary • Involuntary • Voluntary • Normal exit • Error exit • Involuntary • Fatal error (only sort of involuntary) • Killed by another process 8
  • 9. PROCESS TERMINATION • Process executes last statement and then asks the operating system to delete it using the exit() system call. • Returns status data from child to parent (via wait()) • Process’ resources are deallocated by operating system • Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so: • Child has exceeded allocated resources • Task assigned to child is no longer required • The parent is exiting and the operating systems does not allow a child to continue if its parent terminates
  • 10. PROCESS TERMINATION • Some operating systems do not allow a child to exist if its parent has terminated. If a process terminates, then all its children must also be terminated. • cascading termination. All children, grandchildren, etc. are terminated. • The termination is initiated by the operating system. • The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status); • If no parent waiting (did not invoke wait()) process is a zombie • If parent terminated without invoking wait , process is an orphan
  • 11. PROCESS HIERARCHIES • Parent creates a child process • Child processes can create their own children • Forms a hierarchy • UNIX calls this a “process group” • If a process exits, its children are “inherited” by the exiting process’s parent • Windows has no concept of process hierarchy • All processes are created equal 11
  • 12. PROCESS STATES • Process in one of 5 states • Created • Ready • Running • Blocked • Exit • Transitions between states 1 - Process enters ready queue 2 - Scheduler picks this process 3 - Scheduler picks a different process 4 - Process waits for event (such as I/O) 5 - Event occurs 6 - Process exits 7 - Process ended by another process 12 Blocked (waiting) Created Exit Ready Running 1 5 4 3 2 7 7 6
  • 13. PROCESSES IN THE OS • Two “layers” for processes • Lowest layer of process-structured OS handles interrupts, scheduling • Above that layer are sequential processes • Processes tracked in the process table • Each process has a process table entry 13 Scheduler 0 1 N-2 N-1 … Processes
  • 14. WHAT’S IN A PROCESS TABLE ENTRY? 14 File management Root directory Working (current) directory File descriptors User ID Group ID Memory management Pointers to text, data, stack or Pointer to page table Process management Registers Program counter CPU status word Stack pointer Process state Priority / scheduling parameters Process ID Parent process ID Signals Process start time Total CPU usage May be stored on stack
  • 15. WHAT HAPPENS ON A TRAP/INTERRUPT? 1. Hardware saves program counter (on stack or in a special register) 2. Hardware loads new PC, identifies interrupt 3. Assembly language routine saves registers 4. Assembly language routine sets up stack 5. Assembly language calls C to run service routine 6. Service routine calls scheduler 7. Scheduler selects a process to run next (might be the one interrupted…) 8. Assembly language routine loads PC & registers for the selected process 15
  • 16. THREADS: “PROCESSES” SHARING MEMORY • Process == address space • Thread == program counter / stream of instructions • Two examples • Three processes, each with one thread • One process with three threads 16 Kernel Kernel Threads Threads System space User space Process 1 Process 2 Process 3 Process 1
  • 17. PROCESS & THREAD INFORMATION 17 Per process items Address space Open files Child processes Signals & handlers Accounting info Global variables Per thread items Program counter Registers Stack & stack pointer State Per thread items Program counter Registers Stack & stack pointer State Per thread items Program counter Registers Stack & stack pointer State
  • 18. THREADS & STACKS 18 Kernel Process Thread 1 Thread 2 Thread 3 Thread 1’s stack Thread 3’s stack Thread 2’s stack User space => Each thread has its own stack!
  • 19. WHY USE THREADS? • Allow a single application to do many things at once • Simpler programming model • Less waiting • Threads are faster to create or destroy • No separate address space • Overlap computation and I/O • Could be done without threads, but it’s harder • Example: word processor • Thread to read from keyboard • Thread to format document 19 Kernel
  • 20. MULTITHREADED WEB SERVER 20 Kernel Network connection Dispatcher thread Worker thread Web page cache while(TRUE) { getNextRequest(&buf); handoffWork(&buf); } while(TRUE) { waitForWork(&buf); lookForPageInCache(&buf,&page); if(pageNotInCache(&page)) { readPageFromDisk(&buf,&page); } returnPage(&page); }
  • 21. THREE WAYS TO BUILD A SERVER • Thread model • Parallelism • Blocking system calls • Single-threaded process: slow, but easier to do • No parallelism • Blocking system calls • Finite-state machine • Each activity has its own state • States change when system calls complete or interrupts occur • Parallelism • Nonblocking system calls • Interrupts 21
  • 22. IMPLEMENTING THREADS 22 Kernel Run-time system Thread table Process table Kernel Thread Process Thread table Process table User-level threads + No need for kernel support - May be slower than kernel threads - Harder to do non-blocking I/O Kernel-level threads + More flexible scheduling + Non-blocking I/O - Not portable
  • 23. PRODUCER-CONSUMER PROBLEM • Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process
  • 24. BOUNDED-BUFFER – SHARED- MEMORY SOLUTION • Shared data • #define BUFFER_SIZE 10 • typedef struct { • . . . • } item; • item buffer[BUFFER_SIZE]; • int in = 0; • int out = 0; • Solution is correct, but can only use BUFFER_SIZE-1 elements
  • 25. BOUNDED-BUFFER – PRODUCER item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; }
  • 26. BOUNDED BUFFER – CONSUMER item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ } 26
  • 27. SCHEDULING • What is scheduling? • Goals • Mechanisms • Scheduling on batch systems • Scheduling on interactive systems • Other kinds of scheduling • Real-time scheduling 27
  • 28. WHY SCHEDULE PROCESSES? • Bursts of CPU usage alternate with periods of I/O wait • Some processes are CPU-bound: they don’t make many I/O requests • Other processes are I/O-bound and make many kernel requests 28 CPU bound I/O bound CPU bursts I/O waits Total CPU usage Total CPU usage Time
  • 29. WHEN ARE PROCESSES SCHEDULED? • At the time they enter the system • Common in batch systems • Two types of batch scheduling • Submission of a new job causes the scheduler to run • Scheduling only done when a job voluntarily gives up the CPU (i.e., while waiting for an I/O request) • At relatively fixed intervals (clock interrupts) • Necessary for interactive systems • May also be used for batch systems • Scheduling algorithms at each interrupt, and picks the next process from the pool of “ready” processes 29
  • 30. Scheduling goals • All systems • Fairness: give each process a fair share of the CPU • Enforcement: ensure that the stated policy is carried out • Balance: keep all parts of the system busy • Batch systems • Throughput: maximize jobs per unit time (hour) • Turnaround time: minimize time users wait for jobs • CPU utilization: keep the CPU as busy as possible • Interactive systems • Response time: respond quickly to users’ requests • Proportionality: meet users’ expectations • Real-time systems • Meet deadlines: missing deadlines is a system failure! • Predictability: same type of behavior for each time slice 30