Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

Similar documents
Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

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

CS 450 Operating System Week 4 Lecture Notes

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

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

Announcements Processes: Part II. Operating Systems. Autumn CS4023

More on Synchronization and Deadlock

Operating Systems 9/6/ SIGINT Terminate Interrupt from keyboard (ctl-c) 9 SIGKILL Terminate Kill program (cannot override or ignore)

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

Processes. Process Concept

Processes. Dr. Yingwu Zhu

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

Processes and Threads

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

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

Chapter 4: Threads. Chapter 4: Threads

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

Unix API Books. Linux Kernel Books. Assignments and Exams. Grading for CSC 256. Operating Systems 8/31/2018. CSC 256/456 Fall

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

Chapter 4: Multithreaded Programming

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Deadlock. A Bit More on Synchronization. The Deadlock Problem. Deadlock Characterization. Operating Systems 2/7/2005. CSC 256/456 - Spring

CSE 4/521 Introduction to Operating Systems

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

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

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Chapter 4: Processes. Process Concept

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 4: Processes

Chapter 3: Processes

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

Processes and Threads

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

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

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

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

CSE 153 Design of Operating Systems Fall 2018

CS 326: Operating Systems. Process Execution. Lecture 5

Threads. CS3026 Operating Systems Lecture 06

Processes. CS3026 Operating Systems Lecture 05

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

Chapter 4: Threads. Chapter 4: Threads

Basic Memory Management

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

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

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

CSCE 313: Intro to Computer Systems

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

Chapter 4 Multithreaded Programming

Chapter 3: Process Concept

csci3411: Operating Systems

Chap 4, 5: Process. Dongkun Shin, SKKU

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Operating Systems. II. Processes

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

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

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

Chapter 3: Processes

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Processes, Threads, SMP, and Microkernels

CS307: Operating Systems

Dept. Of Computer Science, Colorado State University

CHAPTER 2: PROCESS MANAGEMENT

Frequently asked questions from the previous class survey

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

Frequently asked questions from the previous class survey

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

CSC 539: Operating Systems Structure and Design. Spring 2006

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

W4118 Operating Systems. Junfeng Yang

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

Lecture 4: Process Management

High-level Synchronization

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

Killing Zombies, Working, Sleeping, and Spawning Children

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: Processes and Threads

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

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

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

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

I/O Device Controllers. I/O Systems. I/O Ports & Memory-Mapped I/O. Direct Memory Access (DMA) Operating Systems 10/20/2010. CSC 256/456 Fall

CSE 4/521 Introduction to Operating Systems

Processes and Threads

Process Description and Control

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

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

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

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

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

Lecture 2 Process Management

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

Transcription:

Recap of the Last Class Processes & Threads CS 256/456 Dept. of Computer Science, University of Rochester Hardware protection kernel and user mode System components process management, memory management, I/O system, file and storage, networking, Operating system architectures monolithic architecture, microkernel 1/23/2007 CSC 256/456 - Spring 2007 1 1/23/2007 CSC 256/456 - Spring 2007 2 Microkernel System Architecture Microkernel architecture: Moves as much from the kernel into user space (still protected from normal users). Communication takes place between user modules using message passing. Benefits: More reliable (less code is running in kernel mode) More secure (less code is running in kernel mode) Disadvantage: More overhead in inter-domain communications Layered Structure Layered structure The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware. The highest (layer N) is the user interface. Decreased privileges for higher layers. Benefits: more reliable more secure Disadvantage: Weak integration results in performance penalty (similar to the microkernel structure). 1/23/2007 CSC 256/456 - Spring 2007 3 1/23/2007 CSC 256/456 - Spring 2007 4

Outline Process Process concept A process s image in a computer Operations on processes Thread Thread concept Multithreading models Types of 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 Process a program in execution. A process s state/image in a computer includes: User-mode address space Kernel data structure Registers (including program counter and stack pointer) Address space and memory protection Physical memory is divided into user memory and kernel memory Kernel memory can only be accessed when in the kernel mode Each process has its own exclusive address space in the usermode memory space (sort-of) 1/23/2007 CSC 256/456 - Spring 2007 5 1/23/2007 CSC 256/456 - Spring 2007 6 User-mode Address Space Process Control Block (PCB) User-mode address space for a process: Text: program code, instructions Data: initialized global and static variables (those data whose size is known before the execution) BSS (block started by symbol): uninitialized global and static variables Heap: dynamic memory (those being malloc-ed) Stack: local variables and other stuff for function invocations 0xffffffff 0 Stack Heap BSS Data Text OS data structure (in kernel memory) maintaining information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information Information about open files maybe kernel stack? 1/23/2007 CSC 256/456 - Spring 2007 7 1/23/2007 CSC 256/456 - Spring 2007 8

Process State As a process executes, it changes state new: The process is being created. ready: The process is waiting to be assigned to a process. running: Instructions are being executed. waiting: The process is waiting for some event to occur. terminated: The process has finished execution. Process Creation When a process (parent) creates a new process (child) Execution sequence? Address space sharing? Open files inheritance? UNIX examples fork system call creates new process with a duplicated copy of everything. exec system call used after a fork to replace the process memory space with a new program. child and parent compete CPU like two normal processes. Copy-on-write 1/23/2007 CSC 256/456 - Spring 2007 9 1/23/2007 CSC 256/456 - Spring 2007 10 Process Tree on a Linux System Parent process creates children processes, which, in turn create other processes, forming a tree of processes. System daemon x System daemon y System daemon z init (pid=1) KDE-init user 1 sshd user 2 CPU Switch From Process to Process When can the OS switch the CPU from one process to another? shell 1a shell 1b shell 2c Which one to switch to? - scheduling 1/23/2007 CSC 256/456 - Spring 2007 11 1/23/2007 CSC 256/456 - Spring 2007 12

Queues for PCBs Ready queue set of all processes ready for execution. Device queues set of processes waiting for an I/O device. Process migration between the various queues. Process Termination Process executes last statement and gives the control to the OS (exit). Notify parent if it is wait-ing. Deallocate process resources. The OS may forcefully terminate a process. Software exceptions Receiving certain signals 1/23/2007 CSC 256/456 - Spring 2007 13 1/23/2007 CSC 256/456 - Spring 2007 14 Processes and Threads Thread a program in execution; without a dedicated address space. OS memory protection is only applied to processes. Why Use Threads? Multithreading is used for parallelism/concurrency. But why not multiple processes? Memory sharing. Efficient synchronization between threads Less context switch overhead 1/23/2007 CSC 256/456 - Spring 2007 15 1/23/2007 CSC 256/456 - Spring 2007 16

User/Kernel Threads What is really happening when the execution of one thread switches to another? save the registers (including the SP) of the old thread; restore the registers of the new thread; set the new PC appropriately for the new thread; Does this need help from the OS kernel? Can you do it in C/Java? Does process switching need help from the OS kernel? User threads Thread data structure is in user-mode memory scheduling/switching done at user mode Kernel threads Thread data structure is in kernel memory scheduling/switching done by the OS kernel User/Kernel Threads (cont.) Benefits of user threads lightweight less context switching overhead more efficient synchronization?? flexibility allow application-controlled scheduling Problems of user threads can t use more than one processor oblivious to kernel events, e.g., all threads in a process are put to wait when only one of them does I/O 1/23/2007 CSC 256/456 - Spring 2007 17 1/23/2007 CSC 256/456 - Spring 2007 18 Mixed User/Kernel Threads M user threads run on N kernel threads (M N) N=1: pure user threads M=N: pure kernel threads M>N>1: mixed model user threads Solaris/Linux Threads Solaris supports mixed model Linux No standard user threads on Linux Processes are treated similarly with threads (both called tasks) Processes are tasks with exclusive address space Tasks can also share the address space, open files, kernel threads CPU CPU 1/23/2007 CSC 256/456 - Spring 2007 19 1/23/2007 CSC 256/456 - Spring 2007 20

Pthreads Disclaimer Different OS has its own thread package with different Application Programming Interfaces poor portability. Pthreads A POSIX standard API for thread management and synchronization. API specifies behavior of the thread library, not the implementation. Commonly supported in UNIX operating systems. Parts of the lecture slides contain original work of Abraham Silberschatz, Peter B. Galvin, Greg Gagne, Andrew S. Tanenbaum, and Gary Nutt. The slides are intended for the sole purpose of instruction of operating systems at the University of Rochester. All copyrighted materials belong to their original owner(s). 1/23/2007 CSC 256/456 - Spring 2007 21 1/23/2007 CSC 256/456 - Spring 2007 22