Processes and Threads

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

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

Implementation of Processes

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

Major Requirements of an OS

Processes and Threads

Chapter 2 Processes and Threads

Processes and Threads Implementation

Process Description and Control

Processes and Threads Implementation

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

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

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

IT 540 Operating Systems ECE519 Advanced Operating Systems

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

Processes. CS3026 Operating Systems Lecture 05

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

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

Learning Outcomes. Processes and Threads Implementation. Processes Process s user-level stack and execution state. Threads The Thread Model.

CS510 Operating System Foundations. Jonathan Walpole

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

Process Description and Control

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

2 Processes. 2 Processes. 2 Processes. 2.1 The Process Model. 2.1 The Process Model PROCESSES OPERATING SYSTEMS

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Killing Zombies, Working, Sleeping, and Spawning Children

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

CSCE 313: Intro to Computer Systems

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

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

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

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

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

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

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

CS450/550 Operating Systems

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process?

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

Course Syllabus. Operating Systems, Spring 2016, Meni Adler, Danny Hendler & Amnon Meisels

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

CHAPTER 2: PROCESS MANAGEMENT

SMD149 - Operating Systems

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

Process. Discussion session 3 1/30/2016

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

Jan 20, 2005 Lecture 2: Multiprogramming OS

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

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

CS450/550 Operating Systems

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

OS Main Goals. 10/24/2013 Operating Systems, Beykent University 1

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 5: Threads. Outline

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

What s in a process?

Process Description and Control. Chapter 3

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Mon Sep 17, 2007 Lecture 3: Process Management

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

! The Process Control Block (PCB) " is included in the context,

Chapter 3: Processes. Operating System Concepts 8 th Edition,

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

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

CSC 539: Operating Systems Structure and Design. Spring 2006

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

10/10/ Gribble, Lazowska, Levy, Zahorjan 2. 10/10/ Gribble, Lazowska, Levy, Zahorjan 4

Chapter 4 Threads, SMP, and


Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

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)

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

Lecture 4: Threads; weaving control flow

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Threads Chapter 5 1 Chapter 5

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Chapter 3: Processes

Chapter 4: Multithreaded Programming

W4118 Operating Systems. Junfeng Yang

Sistemi in Tempo Reale

Chapter 3: Processes

CHAPTER 3 - PROCESS CONCEPT

Advanced Operating Systems (CS 202) Scheduling (1)

ECE519 Advanced Operating Systems

Process. Program Vs. process. During execution, the process may be in one of the following states

Operating Systems Overview. Chapter 2

Unit I. Chapter 2: Process and Threads

Chapter 3: Processes. Operating System Concepts 8th Edition,

Threads, SMP, and Microkernels. Chapter 4

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

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

CSE 120 Principles of Operating Systems

Transcription:

Processes and Threads 1

Learning Outcomes An understanding of fundamental concepts of processes and threads 2

Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing reasonable response time Allocate resources to processes Support interprocess communication and user creation of processes 3

Processes and Threads Processes: Also called a task or job Execution of an individual program Owner of resources allocated for program execution Encompasses one or more threads Threads: Unit of execution Can be traced list the sequence of instructions that execute Belongs to a process Executes within it. 4

Execution snapshot of three singlethreaded processes (No Virtual Memory)

Logical Execution Trace

Combined Traces (Actual CPU Instructions) What are the shaded sections?

Summary: The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential processes (with a single thread each) Only one program active at any instant 8

Process and thread models of selected OSes Single process, single thread MSDOS Single process, multiple threads OS/161 as distributed Multiple processes, single thread Traditional unix Multiple processes, multiple threads Modern Unix (Linux, Solaris), Windows Note: Literature (incl. Textbooks) often do not cleanly distinguish between processes and threads (for historical reasons) 10

Process Creation Principal events that cause process creation 1. System initialization Foreground processes (interactive programs) Background processes Email server, web server, print server, etc. Called a daemon (unix) or service (Windows) 2. Execution of a process creation system call by a running process New login shell for an incoming telnet/ssh connection 3. User request to create a new process 4. Initiation of a batch job Note: Technically, all these cases use the same system mechanism to create new processes. 11

Process Termination Conditions which terminate processes 1. Normal exit (voluntary) 2. Error exit (voluntary) 3. Fatal error (involuntary) 4. Killed by another process (involuntary) 12

Process/Thread States Possible process/thread states running blocked ready Transitions between states shown 13

Some Transition Causing Running Ready Voluntary Yield() End of timeslice Running Blocked Waiting for input File, network, Events Waiting for a timer (alarm signal) Waiting for a resource to become available 14

Scheduler Sometimes also called the dispatcher The literature is also a little inconsistent on with terminology. Has to choose a Ready process to run How? It is inefficient to search through all processes 15

The Ready Queue 16

What about blocked processes? When an unblocking event occurs, we also wish to avoid scanning all processes to select one to make Ready 17

Using Two Queues 18

Implementation of Processes A processes information is stored in a process control block (PCB) The PCBs form a process table Sometimes the kernel stack for each process is in the PCB Sometimes some process info is on the kernel stack E.g. registers in the trapframe in OS/161 Reality is much more complex (hashing, chaining, allocation bitmaps, ) P7 P6 P5 P4 P3 P2 P1 P0 20

Implementation of Processes Example fields of a process table entry 21

Threads The Thread Model (a) Three processes each with one thread (b) One process with three threads 22

The Thread Model Separating execution from the environment. Items shared by all threads in a process Items private to each thread 23

Threads Analogy The Hamburger Restaurant 24

Single-Threaded Restaurant Customer Arrives Take Order Start Fries Fries Cook Wait for Customer Blocking operations delay all activities Fries Finish Serve Customer Start Burger Assemble Order Burger Finished Burger Cooks 25

Multithreaded Restaurant Customer Arrives Start Fries Fries Cook Wait for Customer Take Order Fries Finish Serve Customer Assemble Order Start Burger Note: Ignoring synchronisation issues for now Burger Finished Burger Cooks 26

Multithreaded Restaurant with more worker threads Customer Arrives Start Fries Fries Cook Start Fries Fries Cook Fries Finish Fries Finish Wait for Customer Take Order Start Burger Start Burger Burger Finished Burger Cooks Burger Finished Burger Cooks Serve Customer Assemble Order Start Burger Burger Finished Burger Cooks 27

Input Events Finite-State Machine Model Customer Arrives Fries Finish (Event-based model) Take Order Start Fries Serve Customer Non- Blocking actions Burger Finished Assemble Order Start Burger Fries Cook Burger Cooks Wait for Customer External activities 28

The Thread Model Each thread has its own stack 29

Thread Model Local variables are per thread Allocated on the stack Global variables are shared between all threads Allocated in data section Concurrency control is an issue Dynamically allocated memory (malloc) can be global or local Program defined (the pointer can be global or local) 30

Observation: Computation State Thread Model Finite State (Event) Model Customer Start Fries Fries Cook Start Fries Fries Cook Arrives Customer Arrives Start Fries Fries Finish Fries Finish Fries Finish Take Order Serve Customer Wait for Customer Take Order Start Burger Start Burger Burger Finished Assemble Order Start Burger Burger Finished Burger Cooks Burger Finished Burger Cooks Serve Customer Assemble Order Start Burger Fries Cook Burger Cooks Wait for Customer Burger Finished Burger Cooks State implicitly stored on the stack. State explicitly managed by program 31

Thread Usage A word processor with three threads 32

Thread Usage A multithreaded Web server 33

Thread Usage Rough outline of code for previous slide (a) Dispatcher thread (b) Worker thread can overlap disk I/O with execution of other threads 34

Thread Usage Three ways to construct a server 35

Summarising Why Threads? Simpler to program than a state machine Less resources are associated with them than a complete process Cheaper to create and destroy Shares resources (especially memory) between them Performance: Threads waiting for I/O can be overlapped with computing threads Note if all threads are compute bound, then there is no performance improvement (on a uniprocessor) Threads can take advantage of the parallelism available on machines with more than one CPU (multiprocessor) 36