SlideShare une entreprise Scribd logo
1  sur  12
Process
&
Multithreading
Content
1. Process
2. Process State
3. Process Control Block
4. Threads
5. Multithreading Model
6. Linux Threads
Process
A process is running instance of a program.
Process memory is divided into four sections
1. The text section comprises the compiled program code, read
in from non-volatile storage when the program is launched.
2. The data section stores global and static variables, allocated
and initialized prior to executing main.
3. The heap is used for dynamic memory allocation, and is
managed via calls to new, delete, malloc, free, etc.
4. The stack is used for local variables. Space on the stack is
reserved for local variables when they are declared ( at
function entrance or elsewhere, depending on the language ),
and the space is freed up when the variables go out of scope.
Note that the stack is also used for function return values, and
the exact mechanisms of stack management may be language
specific.
Process State
Processes may be in one of 5 states.
 New - The process is in the stage of being created.
 Ready - The process has all the resources available that it needs to run, but the CPU is not
currently working on this process's instructions.
 Running - The CPU is working on this process's instructions.
 Waiting - The process cannot run at the moment, because it is waiting for some resource to
become available or for some event to occur. For example the process may be waiting for
keyboard input, disk access request, inter-process messages, a timer to go off, or a child
process to finish.
 Terminated - The process has completed.
Process Control Block
For each process there is a Process Control Block, PCB, which stores the following types of
process-specific information
 Process State - Running, waiting, etc.
 Process ID, and parent process ID.
 CPU registers and Program Counter - These need to be saved and restored when
swapping processes in and out of the CPU.
 CPU-Scheduling information - Such as priority information and pointers to scheduling
queues.
 Memory-Management information - E.g. page tables or
segment tables.
 Accounting information - user and kernel CPU time consumed,
account numbers, limits, etc.
 I/O Status information - Devices allocated, open file tables,
etc.
Threads
A thread is a basic unit of CPU utilization, consisting of a program counter, a stack,
and a set of registers, ( and a thread ID. )
Multi-threaded applications have multiple threads within a single process,
each having their own program counter, stack and set of registers, but sharing
common code, data, and certain structures such as open files.
Thread (cont.)
Single threaded Process Multithreaded Process
Multithreading Model
There are two types of threads to be managed in a modern system:
 User threads
User threads are supported above the kernel, without kernel support. These are the threads that
application programmers would put into their programs.
 Kernel threads
Kernel threads are supported within the kernel of the OS itself. All modern OSes support kernel level
threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel
system calls simultaneously.
In a specific implementation, the user threads must be mapped to kernel threads, using one of
the following strategies.
 Many to One Model
 One to One Model
 Many to Many Model
Multithreading Model (cont.)
Many-To-One Model
One-To-One Model
Linux and Windows from 95 to XP
Multithreading Model (cont.)
Many-To-Many Model
Many-To-Many two-tier model
IRIX, HP-UX, and Tru64 UNIX
Linux Threads
Linux does not distinguish between processes and threads
 The traditional fork( ) system call completely duplicates a process.
 An alternative system call, clone( ) allows for varying degrees of sharing between the parent and child
tasks, controlled by flags such as those shown in the following table:
 Calling clone( )with no flags set is equivalent to fork( ). Calling clone( ) with CLONE_FS,
CLONE_VM, CLONE_SIGHAND, and CLONE_FILES is equivalent to creating a thread, as all of
these data structures will be shared.
 Linux implements this using a structure task_struct, which essentially provides a level of indirection to
task resources. When the flags are not set, then the resources pointed to by the structure are copied,
but if the flags are set, then only the pointers to the resources are copied, and hence the resources are
shared
Flag Meaning
CLONE_FS File-system information is shared
CLONE_VM The same memory space is shared
CLONE_SIGHAND Signal handlers are shared
CLONE_FILES The set of open files is shared
Questions?

Contenu connexe

Tendances

32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
myrajendra
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
myrajendra
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OS
C.U
 

Tendances (20)

Cache memory principles
Cache memory principlesCache memory principles
Cache memory principles
 
Ui disk & terminal drivers
Ui disk & terminal driversUi disk & terminal drivers
Ui disk & terminal drivers
 
Unit iii
Unit iiiUnit iii
Unit iii
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Memory management
Memory managementMemory management
Memory management
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
01 Introduction
01 Introduction01 Introduction
01 Introduction
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
memory hierarchy
memory hierarchymemory hierarchy
memory hierarchy
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ram
 
Memory management
Memory managementMemory management
Memory management
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
INSTRUCTION SET
INSTRUCTION SETINSTRUCTION SET
INSTRUCTION SET
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OS
 
SYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGSYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSING
 

Similaire à Process & Mutlithreading

Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
LieYah Daliah
 
operatinndnd jdj jjrg-system-1(1) (1).pptx
operatinndnd jdj jjrg-system-1(1) (1).pptxoperatinndnd jdj jjrg-system-1(1) (1).pptx
operatinndnd jdj jjrg-system-1(1) (1).pptx
krishnajoshi70
 
operating system for computer engineering ch3.ppt
operating system for computer engineering ch3.pptoperating system for computer engineering ch3.ppt
operating system for computer engineering ch3.ppt
gezaegebre1
 
Week 11Linux InternalsProcesses, schedulingLecture o.docx
Week 11Linux InternalsProcesses, schedulingLecture o.docxWeek 11Linux InternalsProcesses, schedulingLecture o.docx
Week 11Linux InternalsProcesses, schedulingLecture o.docx
melbruce90096
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
mona_hakmy
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
tech2click
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 

Similaire à Process & Mutlithreading (20)

Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
 
Chapter 22 - Windows XP
Chapter 22 - Windows XPChapter 22 - Windows XP
Chapter 22 - Windows XP
 
operatinndnd jdj jjrg-system-1(1) (1).pptx
operatinndnd jdj jjrg-system-1(1) (1).pptxoperatinndnd jdj jjrg-system-1(1) (1).pptx
operatinndnd jdj jjrg-system-1(1) (1).pptx
 
operating system for computer engineering ch3.ppt
operating system for computer engineering ch3.pptoperating system for computer engineering ch3.ppt
operating system for computer engineering ch3.ppt
 
Chapter 3 chapter reading task
Chapter 3 chapter reading taskChapter 3 chapter reading task
Chapter 3 chapter reading task
 
Week 11Linux InternalsProcesses, schedulingLecture o.docx
Week 11Linux InternalsProcesses, schedulingLecture o.docxWeek 11Linux InternalsProcesses, schedulingLecture o.docx
Week 11Linux InternalsProcesses, schedulingLecture o.docx
 
Chapter 1 Introduction to Operating System Concepts
Chapter 1 Introduction to Operating System ConceptsChapter 1 Introduction to Operating System Concepts
Chapter 1 Introduction to Operating System Concepts
 
Os
OsOs
Os
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
UNIT II.pptx
UNIT II.pptxUNIT II.pptx
UNIT II.pptx
 
Windows 2000
Windows 2000Windows 2000
Windows 2000
 
Structure of processes ppt
Structure of processes pptStructure of processes ppt
Structure of processes ppt
 
Epc 3.ppt
Epc 3.pptEpc 3.ppt
Epc 3.ppt
 
App A
App AApp A
App A
 
Operating system.pptx
Operating system.pptxOperating system.pptx
Operating system.pptx
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Operating System Concepts Presentation
Operating System Concepts PresentationOperating System Concepts Presentation
Operating System Concepts Presentation
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Process & Mutlithreading

  • 2. Content 1. Process 2. Process State 3. Process Control Block 4. Threads 5. Multithreading Model 6. Linux Threads
  • 3. Process A process is running instance of a program. Process memory is divided into four sections 1. The text section comprises the compiled program code, read in from non-volatile storage when the program is launched. 2. The data section stores global and static variables, allocated and initialized prior to executing main. 3. The heap is used for dynamic memory allocation, and is managed via calls to new, delete, malloc, free, etc. 4. The stack is used for local variables. Space on the stack is reserved for local variables when they are declared ( at function entrance or elsewhere, depending on the language ), and the space is freed up when the variables go out of scope. Note that the stack is also used for function return values, and the exact mechanisms of stack management may be language specific.
  • 4. Process State Processes may be in one of 5 states.  New - The process is in the stage of being created.  Ready - The process has all the resources available that it needs to run, but the CPU is not currently working on this process's instructions.  Running - The CPU is working on this process's instructions.  Waiting - The process cannot run at the moment, because it is waiting for some resource to become available or for some event to occur. For example the process may be waiting for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to finish.  Terminated - The process has completed.
  • 5. Process Control Block For each process there is a Process Control Block, PCB, which stores the following types of process-specific information  Process State - Running, waiting, etc.  Process ID, and parent process ID.  CPU registers and Program Counter - These need to be saved and restored when swapping processes in and out of the CPU.  CPU-Scheduling information - Such as priority information and pointers to scheduling queues.  Memory-Management information - E.g. page tables or segment tables.  Accounting information - user and kernel CPU time consumed, account numbers, limits, etc.  I/O Status information - Devices allocated, open file tables, etc.
  • 6. Threads A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers, ( and a thread ID. ) Multi-threaded applications have multiple threads within a single process, each having their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files.
  • 7. Thread (cont.) Single threaded Process Multithreaded Process
  • 8. Multithreading Model There are two types of threads to be managed in a modern system:  User threads User threads are supported above the kernel, without kernel support. These are the threads that application programmers would put into their programs.  Kernel threads Kernel threads are supported within the kernel of the OS itself. All modern OSes support kernel level threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel system calls simultaneously. In a specific implementation, the user threads must be mapped to kernel threads, using one of the following strategies.  Many to One Model  One to One Model  Many to Many Model
  • 9. Multithreading Model (cont.) Many-To-One Model One-To-One Model Linux and Windows from 95 to XP
  • 10. Multithreading Model (cont.) Many-To-Many Model Many-To-Many two-tier model IRIX, HP-UX, and Tru64 UNIX
  • 11. Linux Threads Linux does not distinguish between processes and threads  The traditional fork( ) system call completely duplicates a process.  An alternative system call, clone( ) allows for varying degrees of sharing between the parent and child tasks, controlled by flags such as those shown in the following table:  Calling clone( )with no flags set is equivalent to fork( ). Calling clone( ) with CLONE_FS, CLONE_VM, CLONE_SIGHAND, and CLONE_FILES is equivalent to creating a thread, as all of these data structures will be shared.  Linux implements this using a structure task_struct, which essentially provides a level of indirection to task resources. When the flags are not set, then the resources pointed to by the structure are copied, but if the flags are set, then only the pointers to the resources are copied, and hence the resources are shared Flag Meaning CLONE_FS File-system information is shared CLONE_VM The same memory space is shared CLONE_SIGHAND Signal handlers are shared CLONE_FILES The set of open files is shared