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

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

Processes. CS3026 Operating Systems Lecture 05

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

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

CSC 539: Operating Systems Structure and Design. Spring 2006

Announcements Processes: Part II. Operating Systems. Autumn CS4023

CS 450 Operating System Week 4 Lecture Notes

Chap 4, 5: Process. Dongkun Shin, SKKU

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

Threads Chapter 4. Reading: 4.1,4.4, 4.5

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

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

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

Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking

Threads. CS3026 Operating Systems Lecture 06

CHAPTER 2: PROCESS MANAGEMENT

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

Processes. Dr. Yingwu Zhu

OPERATING SYSTEM. Chapter 4: Threads

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Process Description and Control

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Threads Chapter 5 1 Chapter 5

Processes. Process Concept

Fall 2015 COMP Operating Systems. Lab #3

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

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Processes and Threads

Chapter 4: Threads. Chapter 4: Threads

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CS 326: Operating Systems. Process Execution. Lecture 5

CS307: Operating Systems

Chapter 4: Multithreaded Programming

Operating Systems. Lecture 05

Multithreaded Programming

518 Lecture Notes Week 3

Process Description and Control

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

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

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

OPERATING SYSTEMS: Lesson 4: Process Scheduling

CS Lecture 2! Processes! George Mason University! Fall 2010!

4.8 Summary. Practice Exercises

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

W4118 Operating Systems. Junfeng Yang

ECE519 Advanced Operating Systems

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

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

Processes. Sanzheng Qiao. December, Department of Computing and Software

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Processes and Threads

Chapter 4: Multithreaded

CSE 153 Design of Operating Systems Fall 2018

Processes and Threads

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

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

CS510 Operating System Foundations. Jonathan Walpole

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

Chapter 4: Multi-Threaded Programming

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

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

Chapter 4: Threads. Chapter 4: Threads

Lecture 2 Process Management

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

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

THREADS. Jo, Heeseung

Process Characteristics

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

Operating Systems & Concurrency: Process Concepts

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

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

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

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

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

Operating Systems. II. Processes

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

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

UNIX Processes. by Armin R. Mikler. 1: Introduction

Process Description and Control

Computer Systems II. First Two Major Computer System Evolution Steps

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CISC2200 Threads Spring 2015

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

Threads, SMP, and Microkernels. Chapter 4

Processes COMPSCI 386

CSE 4/521 Introduction to Operating Systems

Chapter 3: Process Concept

Chapter 3: Process Concept

CS5460: Operating Systems

Chapter 4: Processes. Process Concept

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

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

Transcription:

Lecture Topics Today: Threads (Stallings, chapter 4.1-4.3, 4.6) Next: Concurrency (Stallings, chapter 5.1-5.4, 5.7) 1 Announcements Make tutorial Self-Study Exercise #4 Project #2 (due 9/20) Project #3 (due 9/27) 2

UNIX Process Management Two categories of processes System processes run in kernel mode for housekeeping functions (memory allocation, process swapping, etc) User processes run in user mode for user programs run in kernel mode for system calls, traps, interrupts 3 UNIX System Processes Process 0 is created at boot time and becomes the "swapper'' process after forking process 1 (the "systemd" process) and process 2 (the "kthreadd" process) The "kthreadd" process is the ancestor of all kernel processes The "systemd" process is the ancestor of all user processes 4

UNIX Process Creation Every process (except process 0) is created by the fork() system call fork() allocates entry in process table and assigns a unique PID to the child process child gets a copy of the process image of the parent; both child and parent are executing the same code after fork() fork() returns the PID of the child process to the parent process and returns 0 to the child process 5 UNIX Process Creation int pid = fork(); if (pid < 0) { // Error -- fork failed } else if (pid > 0) { // Parent process (pid contains child's PID) } else { // Child process } 6

UNIX Process Creation When the child process terminates, the parent process is notified Typically, the parent process uses the wait() system call to voluntarily block until the child process terminates If the parent process terminates before the child process, the child becomes an orphan process and is adopted by process 1 7 UNIX Process Specialization The fork() system call creates a duplicate copy of the process image of the parent; both child and parent are executing the same code after fork() The exec() family of system calls is used to replace the process image of one process (usually the child) with a different process image (a different program) 8

UNIX Process Specialization int pid = fork(); if (pid < 0) { // Error -- fork failed } else if (pid > 0) { // Parent process (pid contains child's PID) } else { flag = execvp( "ls", args ); } 9 Main Process Characteristics Resource ownership: virtual address space to hold the process image control of some resources (files, I/O devices...) Execution: path (trace) through object code execution interleaved with other processes execution context saved in PCB when the process is interrupted 10

Main Process Characteristics In modern operating systems, these two characteristics are often treated independently The unit of dispatching is usually referred to as a thread or (lightweight process) The unit of resource ownership is usually referred to as a process (or task) 11 Multithreading vs Single Threading Single threading: the OS does not recognize the concept of threads MS-DOS supports a single thread Traditional UNIX supports multiple user processes but only supports one thread per process Linux, Windows, Solaris, Mach, and OS/2 support multiple threads 12

Processes and Threads 13 Process A virtual address space which holds the process image Protected access to processors, other processes, files, and I/O resources 14

Thread An execution state (running, ready, etc.) Saved thread context when not running An execution stack Static storage for local variables Access to memory and resources of its process (shared by all threads) 15 Thread Viewpoint: thread is an independent program counter (and other context) within a process All threads within a process share the process resources when one thread alters a (non-private) memory item, all other threads (of the process) see it a file opened by one thread is available to others 16

Threaded Process Models 17 Benefits of Threads Less effort to create a new thread than a new process Less effort to terminate a thread Less effort to switch between two threads within the same process Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel 18

Benefits of Threads Consider an application that consists of several independent parts that do not need to run in sequence Each part can be implemented as a thread Whenever one thread is blocked waiting for I/O, execution could switch to another thread of the same application (instead of switching to another process) 19 Example Applications Web server must handle several requests over a short period more efficient to create (and destroy) a single thread for each request Menu-driven program thread to display menu, read user input thread(s) to execute user commands 20

Linux Processes and Threads There is no distinction between processes and threads in Linux: the term task is used to refer to both One task can create another task by cloning itself (clone() is a more flexible version of fork() can specify degree of resource sharing) 21 Linux Task States 22

Linux Task States Ready ready to use the CPU Running using the CPU Uninterruptible waiting on hardware Interruptible waiting for resource or signal Stopped waiting for another process to restart it (for debugging) Zombie terminated, waiting for system to get info from PCB 23 Examples threads1.c threads2.c threads3.c threads4.c threads5.c threads6.c 24