Chapter 2 Processes and Threads

Similar documents
Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

CS450/550 Operating Systems

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

CS450/550 Operating Systems

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL. Chap. 2.2 Interprocess Communication

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

C09: Process Synchronization

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Processes and Threads. Processes: Review

Main Points of the Computer Organization and System Software Module

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for s,...).

Midterm Exam. October 20th, Thursday NSC

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


Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Processes and Threads

Synchronization COMPSCI 386

Operating Systems Structure

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

Unit I. Chapter 2: Process and Threads

Processes and Threads

CHAPTER NO - 1 : Introduction:

Department of Computer applications. [Part I: Medium Answer Type Questions]

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

System Call. Preview. System Call. System Call. System Call 9/7/2018

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

CS370 Operating Systems

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

Chapter 2 - Processes and Threads

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

8: Scheduling. Scheduling. Mark Handley

Advanced Operating Systems (CS 202) Scheduling (1)

PROCESS SYNCHRONIZATION

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

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

UNIT 2 Basic Concepts of CPU Scheduling. UNIT -02/Lecture 01

CSI3131 Final Exam Review

MARUTHI SCHOOL OF BANKING (MSB)

CSE 153 Design of Operating Systems

Timers 1 / 46. Jiffies. Potent and Evil Magic

Major Requirements of an OS

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

OS Process Synchronization!

148 PROCESSES CHAP. 2

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

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

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Chendu College of Engineering & Technology

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Dealing with Issues for Interprocess Communication

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Course Description: This course includes the basic concepts of operating system

Lecture 9: Midterm Review

CS370 Operating Systems Midterm Review

Uniprocessor Scheduling

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

Chapters 5 and 6 Concurrency

Concurrency and Synchronisation

Concurrency and Synchronisation

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

CS 370 Operating Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Concept of a process

Process. A Program In Execution. Program is a set of instructions.

1.1 CPU I/O Burst Cycle

INSTITUTE OF AERONAUTICAL ENGINEERING

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Operating Systems: Quiz2 December 15, Class: No. Name:

CS370 Operating Systems

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Dept. of CSE, York Univ. 1

User-level threads are threads that are visible to a programmer and are unknown to the kernel OS kernel supports and manages kernel-level threads

Student Name:.. Student ID... Course Code: CSC 227 Course Title: Semester: Fall Exercises Cover Sheet:

IV. Process Synchronisation

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS370 Operating Systems

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad COMPUTER SCIENCE AND ENGINEERING QUESTION BANK OPERATING SYSTEMS

Synchronization I. Jo, Heeseung

CSE 120 Principles of Operating Systems Spring 2017

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

QUESTION BANK UNIT I

CS604 - Operating System Solved Subjective Midterm Papers For Midterm Exam Preparation

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Transcription:

MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads

The Process Model Figure 2-1. (a) Multiprogramming of four programs. (b) Conceptual model of four independent, sequential processes. (c) Only one program is active at once.

Process Creation Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to create a new process. 4. Initiation of a batch job.

Process Termination Events which cause process termination 1. Normal exit (voluntary). 2. Error exit (voluntary). 3. Fatal error (involuntary). 4. Killed by another process (involuntary).

Process States Figure 2-2. A process can be in running, blocked, or ready state. Transitions between these states are as shown.

Implementation of Processes (1) Figure 2-3. The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer are sequential processes.

Implementation of Processes (2) Figure 2-4. Some of the fields of a typical process table entry.

Implementation of Processes (3) Figure 2-5. Skeleton of what the lowest level of the operating system does when an interrupt occurs.

Modeling Multiprogramming Figure 2-6. CPU utilization as a function of the number of processes in memory.

Thread Usage (1) Figure 2-7. A word processor with three threads.

Thread Usage (2) Figure 2-8. A multithreaded Web server.

Thread Usage (3) Figure 2-9. A rough outline of the code for Fig. 2-8. (a) Dispatcher thread. (b) Worker thread.

Thread Usage (4) Figure 2-10. Three ways to construct a server.

The Classical Thread Model (1) Figure 2-11. (a) Three processes each with one thread. (b) One process with three threads.

The Classical Thread Model (2) Figure 2-12. The first column lists some items shared by all threads in a process. The second one lists some items private to each thread.

The Classical Thread Model (3) Figure 2-13. Each thread has its own stack.

POSIX Threads (1) Figure 2-14. Some of the Pthreads function calls.

POSIX Threads (2)... Figure 2-15. An example program using threads.

... POSIX Threads (3) Figure 2-15. An example program using threads.

Implementing Threads in User Space Figure 2-16. (a) A user-level threads package. (b) A threads package managed by the kernel.

Hybrid Implementations Figure 2-17. Multiplexing user-level threads onto kernel-level threads.

Pop-Up Threads Figure 2-18. Creation of a new thread when a message arrives. (a) Before the message arrives. (b) After the message arrives.

Making Single-Threaded Code Multithreaded (1) Figure 2-19. Conflicts between threads over the use of a global variable.

Making Single-Threaded Code Multithreaded (2) Figure 2-20. Threads can have private global variables.

Race Conditions Figure 2-21. Two processes want to access shared memory at the same time.

Critical Regions (1) Conditions required to avoid race condition 1. No two processes may be simultaneously inside their critical regions. 2. No assumptions may be made about speeds or the number of CPUs. 3. No process running outside its critical region may block other processes. 4. No process should have to wait forever to enter its critical region.

Critical Regions (2) Figure 2-22. Mutual exclusion using critical regions.

Mutual Exclusion with Busy Waiting Proposals for achieving mutual exclusion 1. Disabling interrupts 2. Lock variables 3. Strict alternation 4. Peterson's solution 5. The TSL instruction

Strict Alternation Figure 2-23. A proposed solution to the critical region problem. (a) Process 0. (b) Process 1. In both cases, be sure to note the semicolons terminating the while statements.

Peterson's Solution Figure 2-24. Peterson s solution for achieving mutual exclusion.

The TSL Instruction (1) Figure 2-25. Entering and leaving a critical region using the TSL instruction.

The TSL Instruction (2) Figure 2-26. Entering and leaving a critical region using the XCHG instruction.

The Producer-Consumer Problem (1)... Figure 2-27. The producer-consumer problem with a fatal race condition.

The Producer-Consumer Problem (2)... Figure 2-27. The producer-consumer problem with a fatal race condition.

Semaphores (1)... Figure 2-28. The producer-consumer problem using semaphores.

Semaphores (2)... Figure 2-28. The producer-consumer problem using semaphores.

Mutexes Figure 2-29. Implementation of mutex lock and mutex unlock.

Mutexes in Pthreads (1) Figure 2-30. Some of the Pthreads calls relating to mutexes.

Mutexes in Pthreads (2) Figure 2-31. Some of the Pthreads calls relating to condition variables.

Mutexes in Pthreads (3)... Figure 2-32. Using threads to solve the producer-consumer problem.

Mutexes in Pthreads (4)...... Figure 2-32. Using threads to solve the producer-consumer problem.

... Mutexes in Pthreads (5) Figure 2-32. Using threads to solve the producer-consumer problem.

Monitors (1) Figure 2-33. A monitor.

Monitors (2) Figure 2-34. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots.

Monitors (3) Figure 2-34. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots.

Message Passing (1)... Figure 2-35. A solution to the producer-consumer problem in Java.

... Message Passing (2)... Figure 2-35. A solution to the producer-consumer problem in Java.

Message Passing (3)... Figure 2-35. A solution to the producer-consumer problem in Java.

Producer-Consumer Problem with Message Passing (1)... Figure 2-36. The producer-consumer problem with N messages.

... Producer-Consumer Problem with Message Passing (2) Figure 2-36. The producer-consumer problem with N messages.

Barriers Figure 2-37. Use of a barrier. (a) Processes approaching a barrier. (b) All processes but one blocked at the barrier. (c) When the last process arrives at the barrier, all of them are let through.

Scheduling Process Behavior Figure 2-38. Bursts of CPU usage alternate with periods of waiting for I/O. (a) A CPU-bound process. (b) An I/O-bound process.

Categories of Scheduling Algorithms 1. Batch 2. Interactive 3. Real time

Scheduling Algorithm Goals Figure 2-39. Some goals of the scheduling algorithm under different circumstances.

Scheduling in Batch Systems First-come first-served Shortest job first Shortest remaining Time next

Shortest Job First Figure 2-40. An example of shortest job first scheduling. (a) Running four jobs in the original order. (b) Running them in shortest job first order.

Scheduling in Interactive Systems Round-robin scheduling Priority scheduling Multiple queues Shortest process next Guaranteed scheduling Lottery scheduling Fair-share scheduling

Round-Robin Scheduling Figure 2-41. Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable processes after B uses up its quantum.

Priority Scheduling Figure 2-42. A scheduling algorithm with four priority classes.

Thread Scheduling (1) Figure 2-43. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per CPU burst.

Thread Scheduling (2) Figure 2-43. (b) Possible scheduling of kernel-level threads with the same characteristics as (a).

Dining Philosophers Problem (1) Figure 2-44. Lunch time in the Philosophy Department.

Dining Philosophers Problem (2) Figure 2-45. A nonsolution to the dining philosophers problem.

Dining Philosophers Problem (3)... Figure 2-46. A solution to the dining philosophers problem.

Dining Philosophers Problem (4)...... Figure 2-46. A solution to the dining philosophers problem.

Dining Philosophers Problem (5)... Figure 2-46. A solution to the dining philosophers problem.

The Readers and Writers Problem (1)... Figure 2-47. A solution to the readers and writers problem.

The Readers and Writers Problem (2)... Figure 2-47. A solution to the readers and writers problem.