Chapter 3 Process Description and Control

Similar documents
Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Threads Chapter 4. Reading: 4.1,4.4, 4.5

ECE519 Advanced Operating Systems

Threads Chapter 5 1 Chapter 5

Chapter 4 Threads, SMP, and

Process Description and Control

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

IT 540 Operating Systems ECE519 Advanced Operating Systems

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

4. Concurrency via Threads

CSE 306/506 Operating Systems Threads. YoungMin Kwon

Threads, SMP, and Microkernels

Chapter 3 Process Description and Control

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

2017 Pearson Educa2on, Inc., Hoboken, NJ. All rights reserved.

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Threads, SMP, and Microkernels. Chapter 4

Processes and Threads

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

Definition Multithreading Models Threading Issues Pthreads (Unix)

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Processes, Threads, SMP, and Microkernels

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1

Chapter 4: Multi-Threaded Programming

Process Description and Control. Chapter 3

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

CS 450 Operating System Week 4 Lecture Notes

Operating System Control Structures

OPERATING SYSTEM. Chapter 4: Threads

Process Characteristics

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Operating Systems. Lecture 3- Process Description and Control. Masood Niazi Torshiz

Operating Systems. Lecture 4. Nachos Appetizer

Announcement. Exercise #2 will be out today. Due date is next Monday

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Threads. studykorner.org

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Chapter 4: Threads. Chapter 4: Threads

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

Major Requirements of an OS

Threads. CS3026 Operating Systems Lecture 06

CSE 153 Design of Operating Systems Fall 2018

Process Description and Control

Process Description and Control. Chapter 3

CHAPTER 2: PROCESS MANAGEMENT

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Processes and Threads. Processes: Review

Chapter 4: Multithreaded Programming

Chapter 4: Threads. Operating System Concepts 8 th Edition,

Processes and Threads

Process Description and Control

Multithreaded Programming

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

SMD149 - Operating Systems

Chapter 4: Threads. Chapter 4: Threads

Computer Systems Laboratory Sungkyunkwan University

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1)

Yi Shi Fall 2017 Xi an Jiaotong University

Chapter 5: Threads. Outline

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

CSE 120 Principles of Operating Systems

Threads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Threads Assistant Professor DCS Operating System Concepts

Chapter 3 Process Description and Control

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

CSE 4/521 Introduction to Operating Systems

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

3.1 Introduction. Computers perform operations concurrently

Process. Discussion session 3 1/30/2016

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

CSE 120 Principles of Operating Systems

Chapter 4: Multithreaded Programming Dr. Varin Chouvatut. Operating System Concepts 8 th Edition,

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

THREADS. Jo, Heeseung

Operating System 4 THREADS, SMP AND MICROKERNELS

DISTRIBUTED COMPUTER SYSTEMS

CS420: Operating Systems

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

Chapter 4: Threads. Operating System Concepts 9 th Edition

Process Description and Control

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Chapter 4: Threads. Operating System Concepts 9 th Edition

!! How is a thread different from a process? !! Why are threads useful? !! How can POSIX threads be useful?

Transcription:

Operating Systems: Internals and Design Principles Chapter 3 Process Description and Control Seventh Edition By William Stallings

Process Control Block

Structure of Process Images in Virtual Memory

How to do SWITCH??? 1.Mode Switch 2.Context Switch 3.Process Switch

Context Switch save the context of the processor update the process control block of the process currently in the Running state move the process control block of this process to the appropriate queue If the currently running process is to be moved to another state (Ready, Blocked, etc.), then the OS must make substantial changes in its environment select another process for execution restore the context of the processor to that which existed at the time the selected process was last switched out update memory management data structures update the process control block of the process selected

Mode Switch If no interrupts are pending the processor: If an interrupt is pending the processor: proceeds to the fetch stage and fetches the next instruction of the current program in the current process Saves the context of the current program being executed. sets the program counter to the starting address of an interrupt handler program switches from user mode to kernel mode so that the interrupt processing code may include privileged instructions

Process Switch A process switch may occur any time that the OS has gained control from the currently running process. Possible events giving OS control are: Due to some sort of event that is external to and independent of the currently running process clock interrupt I/O interrupt memory fault Time slice the maximum amount of time that a process can execute before being interrupted An error or exception condition generated within the currently running process OS determines if the condition is fatal moved to the Exit state and a process switch occurs action will depend on the nature of the error

Process Switch A process switch may occur any time that the OS has gained control from the currently running process. Steps: 1. Save the Current state 2. Give control the new process 3. Restore the previous state. What is the difference between Mode switch and Process switch?

Non-Process Kernel Types of Exe within Userprocess Kernel Process based Kernel

Cooperating Processes Independent process cannot affect or be affected by the execution of another process. Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up via parallel sub-tasks Modularity by dividing system functions into separate processes Convenience - even an individual may want to edit, print and compile in parallel

Operating Systems: Internals and Design Principles Chapter 4 Process and Threads Seventh Edition By William Stallings

Process and Threads Process The unit or resource allocation and a unit of protection The key states for a Process are: Running Ready Blocked Suspended Exit Process operations are: Create Terminate Spawn. Thread The unit of dispatching is referred to as a thread or lightweight process The key states for a thread are: Running Ready Blocked Thread operations associated with a change in thread state are: Spawn Block Unblock Finish

P R O C E S S & T H R E A D S

Process has PCB and Address space Thread has TCB and Stacks

Benefits of THREADS Takes less time to create a new thread than a process Less time to terminate a thread than a process Switching between two threads takes less time than switching between processes Threads enhance efficiency in communication between programs

Types of Threads User Level Thread (ULT) Kernel level Thread (KLT)

Comparison KLTs 1. Kernel is aware of the presence of KLT 2. Thread management is done by the kernel 3. If one thread in a process is blocked, the kernel can schedule another thread of the same process ULTs 1. The kernel is not aware of the existence of threads 2. All thread management is done by the application (Thread Library; A package of routines for ULT) 3. In a typical OS many system calls are blocking as a result, when a ULT executes a system call, not only is that thread blocked, but all of the threads within the process are blocked

Difference and Similarities KLTs 4. Can run on specific OS 5. The kernel can simultaneously schedule multiple threads from the same process on multiple processors 6. The transfer of control from one thread to another within the same process requires a mode switch to the kernel 7. Examples are: Windows NT ULTs 4. ULTs can run on any OS 5. In a pure ULT strategy, a multithreaded application cannot take advantage of multiprocessing (multi-processor or multi-core) 6. Thread switching does not require kernel mode privileges 7. Examples are: DCE Thread library

Relationships Between ULT States and Process States

Pictorial view

Combined Approaches Thread creation is done in the user space Bulk of scheduling and synchronization of threads is by the application Solaris is an example

Solaris Process Process User-level Threads Lightweight Processes (LWP) Kernel Threads includes the user s address space, stack, and process control block a user-created unit of execution within a process a mapping between ULTs and kernel threads fundamental entities that can be scheduled and dispatched to run on one of the system processors

Processes and Threads in Solaris

A Lightweight Process (LWP) Data Structure Includes: 1. An LWP identifier 2. The priority of this LWP 3. A signal mask 4. Saved values of user-level registers 5. The kernel stack for this LWP 6. Resource usage and profiling data 7. Pointer to the corresponding kernel thread 8. Pointer to the process structure

User-Level Threads Thread management is done by user-level threads library without the intervention of the kernel Fast to create and manage If the kernel is single threaded, any user-level thread performing a blocking system call will cause the entire process to be blocked User thread libraries POSIX Pthreads Mach C-threads Solaris 2 UI-threads

Kernel-Level Threads Supported by the Kernel Slower to create and manage than user threads If thread performs a blocking system call, the kernel can schedule another thread in the application for execution In multi-processor environments, the kernel can schedule threads on multiple processors Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux

Relationship Between Threads and Processes

Implementation of Threads in Java public class Mythread { public static void main(string args[]) { SomeThread p1=new SomeThread(1); p1.start(); SomeThread p2=new SomeThread(2); p2.start(); SomeThread p3=new SomeThread(3); p3.start(); } } class SomeThread extends Thread { int myid; SomeThread(int id) { this.myid=id; } public void run(){ int i; for(i=1;i<10;i++) System.out.println ("Thread" + myid + ":" + i); } }

Java Threads Java threads may be created by extending the Thread class or implementing the Runnable interface Java threads are managed by the JVM

Thread Run Trace Thread2:1 Thread2:2 Thread3:1 Thread3:2 Thread3:3 Thread3:4 Thread3:5 Thread3:6 Thread3:7 Thread3:8 Thread3:9 Thread1:1 Thread2:3 Thread2:4 Thread2:5 Thread1:2 Thread1:3 Thread2:6 Thread1:4 Thread1:5 Thread2:7 Thread1:6 Thread1:7 Thread2:8 Thread1:8 Thread1:9 Thread2:9

Summary User-level threads created and managed by a threads library that runs in the user space of a process a mode switch is not required to switch from one thread to another only a single user-level thread within a process can execute at a time if one thread blocks, the entire process is blocked Kernel-level threads threads within a process that are maintained by the kernel a mode switch is required to switch from one thread to another multiple threads within the same process can execute in parallel on a multiprocessor blocking of a thread does not block the entire process Process/related to resource ownership Thread/related to program execution