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

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

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

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

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

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

Processes and Threads

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

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

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

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

Chapter 4: Processes. Process Concept

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

More on Synchronization and Deadlock

Chapter 4: Multithreaded Programming

Chapter 4: Processes

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

CS 450 Operating System Week 4 Lecture Notes

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Process Description and Control

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

Chapter 3: Processes

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

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

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

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

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

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

CSC 539: Operating Systems Structure and Design. Spring 2006

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

CHAPTER 3 - PROCESS CONCEPT

Chapter 4: Threads. Chapter 4: Threads

W4118 Operating Systems. Junfeng Yang

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

Last Class. System Calls, Kernel Mode, and Process Implementation. Processes. Today. Operating Systems 9/11/2018 CSC 256/456 1

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

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

Dept. Of Computer Science, Colorado State University

Frequently asked questions from the previous class survey

Chapter 3: Processes. Operating System Concepts 8th Edition

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

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Chapter 4: Threads. Chapter 4: Threads

Processes. Process Concept

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

CSE 153 Design of Operating Systems Fall 2018

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

CSE 4/521 Introduction to Operating Systems

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

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

CSC Operating Systems Fall Lecture - II OS Structures. Tevfik Ko!ar. Louisiana State University. August 27 th, 2009.

Announcements. Computer System Organization. Roadmap. Major OS Components. Processes. Tevfik Ko!ar. CSC Operating Systems Fall 2009

Chapter 3: Processes

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

Chapter 3: Processes

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

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

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

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

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

CS 326: Operating Systems. Process Execution. Lecture 5

Threads. CS3026 Operating Systems Lecture 06

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

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

Diagram of Process State Process Control Block (PCB)

Threads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

OS Design Approaches. Roadmap. OS Design Approaches. Tevfik Koşar. Operating System Design and Implementation

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Processes. Dr. Yingwu Zhu

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

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

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

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

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

Chapter 5: Threads. Outline

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

OPERATING SYSTEM. Chapter 4: Threads

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

Chapter 4 Multithreaded Programming

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

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

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

Operating System Design

Processes and Threads

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

ICS Principles of Operating Systems

Transcription:

Recap of the Last Class System protection and kernel mode System calls and the interrupt interface Processes Process concept A process s image in a computer Operations on processes Context switches and the scheduling process 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) 9/11/2012 CSC 2/456 29 9/11/2012 CSC 2/456 30 Process Management A process is a program in execution Unit of work A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task Protection domain OS responsibilities for process management: Process creation and deletion Process scheduling, suspension, and resumption Process synchronization, inter-process communication 9/11/2012 CSC 2/456 31 Private Address Spaces Each process has its own private address space. 0xffffffff 0xc0000000 0x40000000 kernel virtual memory (code, data, heap, stack) user stack (created at runtime) memory mapped region for shared libraries run-time heap (managed by malloc) read/write segment (.data,.bss) memory invisible to user code %esp (stack pointer) read-only segment 0x08048000 (.init,.text,.rodata) 9/11/2012 0 unused CSC 2/456 32 brk loaded from the executable file CSC 256/456 - Fall 2012 1

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 Stack Heap BSS Data 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? 0 Text 9/11/2012 CSC 2/456 33 9/11/2012 CSC 2/456 34 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. Queues for PCBs 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 9/11/2012 CSC 2/456 35 9/11/2012 CSC 2/456 36 CSC 256/456 - Fall 2012 2

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 for CPU like two normal processes. Copy-on-write Today Context switches and the scheduling process Inter-process communication Shared memory Thread Thread concept Multithreading models Types of threads 9/11/2012 CSC 2/456 37 9/11/2012 CSC 2/456 38 Context Switching Processes are managed by a shared chunk of OS code called the kernel Important: the kernel is not a separate process, but rather runs as part of some user process Control flow passes from one process to another via a context switch. Time Process A code Process B code user code kernel code user code kernel code user code context switch context switch 9/11/2012 CSC 2/456 39 Scheduling: Transferring Context Blocks Coroutines transfer(other) save all callee-saves registers on stack, including ra and fp *current := sp current := other sp := *current pop all callee-saves registers (including ra, but NOT sp!) return (into different coroutine!) 9/11/2012 CSC 2/456 40 CSC 256/456 - Fall 2012 3

Uniprocessor Scheduling Preemption Use Ready List to reschedule voluntarily (cooperative threading) reschedule: t : cb := dequeue(ready_list) transfer(t) yield: enqueue(ready_list, current) reschedule sleep_on(q): enqueue(q, current) reschedule Use timer interrupts or signals to trigger involuntary yields Protect scheduler data structures by disabling/reenabling prior to/after rescheduling yield: disable_signals enqueue(ready_list, current) reschedule re-enable_signals 9/11/2012 CSC 2/456 41 9/11/2012 CSC 2/456 42 When can the OS switch the CPU from one process to another? Which one to switch to? - scheduling CPU Switch From Process to Process Process Termination Process executes last statement and gives the control to the OS (exit) Notify parent if it is wait-ing Deallocate process s resources The OS may forcefully terminate a process. Software exceptions Receiving certain signals 9/11/2012 CSC 2/456 43 9/11/2012 CSC 2/456 44 CSC 256/456 - Fall 2012 4

Interprocess Communication Reasons for processes to cooperate Information sharing (e.g., files) Computation speedup Modularity and protection Convenience - multitasking Mechanisms for Interprocess Communication Shared memory Message passing Pipes, sockets, remote procedure calls 9/11/2012 CSC 2/456 45 9/11/2012 CSC 2/456 46 Shared Memory: POSIX interface shm_get returns the identifier of a shared memory segment shmat attaches the shared memory segment to the address space shmdt detaches the segment located at the specified address shmctl control of shared memory segments, including deletion Other possibilities: mmap (file sharing with preserved properties) 9/11/2012 CSC 2/456 47 Message Passing Direct or indirect communication processes or ports Fixed or variable size Send by copy or reference Automatic or explicit buffering Blocking or non-blocking (send or receive) Examples: client-server sockets, Mach ports, Windows 2000 local procedure call (LPC), remote procedure call (RPC, RMI) 9/11/2012 CSC 2/456 48 CSC 256/456 - Fall 2012 5

Processes or Threads A process or thread is a potentially-active execution context Processes/threads can come from Multiple CPUs Kernel-level multiplexing of single physical CPU (kernel-level threads or processes) Language or library-level multiplexing of kernel-level abstraction (user-level threads) Threads can run Truly in parallel (on multiple CPUs) Unpredictably interleaved (on a single CPU) Run-until-block (coroutine-style) Processes and Threads Thread a program in execution; without a dedicated address space. OS memory protection is only applied to processes. 9/11/2012 CSC 2/456 49 9/11/2012 CSC 2/456 50 Processes Vs. Threads Why Use Threads? Process Single address space Single thread of control for executing program State information Page tables, swap images, file descriptors, queued I/O requests, saved registers Threads Separate notion of execution from the rest of the definition of a process Other parts potentially shared with other threads Program counter, stack of activation records, control block (e.g., saved registers/state info for thread management) Kernel-level (lightweight process) handled by the system scheduler User-level handled in user mode Multithreading is used for parallelism/concurrency. But why not multiple processes? Memory sharing. Efficient synchronization between threads Less context switch overhead 9/11/2012 CSC 2/456 51 9/11/2012 CSC 2/456 52 CSC 256/456 - Fall 2012 6

User/Kernel Threads 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 9/11/2012 CSC 2/456 53 9/11/2012 CSC 2/456 54 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 and threads treated in a similar manner (both called tasks) Processes are tasks with exclusive address space Tasks can also share the address space, open files, kernel threads CPU CPU 9/11/2012 CSC 2/456 55 9/11/2012 CSC 2/456 56 CSC 256/456 - Fall 2012 7

Pthreads Each 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. Issues with the Threading Model Thread-local storage what about globals? Stack management Interaction with fork and exec system calls Two versions of fork? Signal handling which thread should the signal be delivered to? Synchronous All Assigned thread Unix: could assign a specific thread to handle signals Windows: asynchronous procedure calls, which are thread-specific 9/11/2012 CSC 2/456 57 9/11/2012 CSC 2/456 58 Disclaimer Parts of the lecture slides contain the original work of Kai Shen, 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). 9/11/2012 CSC 2/456 59 CSC 256/456 - Fall 2012 8