W4118 Operating Systems. Junfeng Yang

Similar documents
Processes and Non-Preemptive Scheduling. Otto J. Anshus

CSE 153 Design of Operating Systems Fall 2018

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

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

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Processes COMPSCI 386

Disciplina Sistemas de Computação

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

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

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

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

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

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

CSE325 Principles of Operating Systems. Processes. David P. Duggan February 1, 2011

What is a Process? Processes and Process Management Details for running a program

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Operating System Structure

Processes. Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

COMP 3100 Operating Systems

Chapter 3: Process Concept

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

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

CSC369 Lecture 2. Larry Zhang

3.1 Introduction. Computers perform operations concurrently

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

CSC369 Lecture 2. Larry Zhang, September 21, 2015

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

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

CSI Module 2: Processes

CSE 410: Systems Programming

Processes and Threads

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

Operating Systems. Review ENCE 360

CS 326: Operating Systems. Process Execution. Lecture 5

Prepared by Prof. Hui Jiang (COSC3221) 2/9/2007

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

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

W4118: OS Overview. Junfeng Yang

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

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

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

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

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

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

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

Operating System Design

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

Chapter 5: Threads. Outline

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

Processes and Threads

SMD149 - Operating Systems

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

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

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

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

Announcements/Reminders

Process Description and Control

Process Time. Steven M. Bellovin January 25,

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

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

csci3411: Operating Systems

CS5460: Operating Systems

Processes. CS3026 Operating Systems Lecture 05

Lecture 4: Memory Management & The Programming Interface

Lecture 2: Processes. CSE 120: Principles of Opera9ng Systems. UC San Diego: Summer Session I, 2009 Frank Uyeda

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

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

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Lecture 4: Process Management

CS240: Programming in C

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Processes. Dr. Yingwu Zhu

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Inter-process communication (IPC)

Signal Example 1. Signal Example 2

Chapter 3: Processes

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

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

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

Chap 4, 5: Process. Dongkun Shin, SKKU

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

Course: Operating Systems Instructor: M Umair. M Umair

Killing Zombies, Working, Sleeping, and Spawning Children

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003

CSC 539: Operating Systems Structure and Design. Spring 2006

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

Computer System Overview

CSCE 313: Intro to Computer Systems

Transcription:

W4118 Operating Systems Junfeng Yang

What is a process? Outline Process dispatching Common process operations Inter-process Communication

What is a process Program in execution virtual CPU Process: an execution stream in the context of a particular process state Execution stream: a stream of instructions Running piece of code sequential sequence of instructions Process state: determines the effect of running code Stuff the running code can affect or be affected by

Process state Registers General purpose, floating point, instruction pointer (program counter) Memory: everything a process can address Code, data, stack, heap, I/O status: File descriptor table,

Program v.s. process Program!= process Program: static code + static data Process: dynamic instantiation of code + data + more Program process: no 1:1 mapping Process > program: more than code and data Program > process: one program runs many processes Process > program: many processes of same program

Address Space Address Space (AS): all memory a process can address Really large memory to use Linear array of bytes: [0, N), N roughly 2^32, 2^64 Process address space: 1 : 1 mapping Key: an AS is a protection domain OS isolates address spaces One process can t access another process s address space Same pointer address in different processes point to different memory

Address space examples Process A Process B

Process v.s. Thread Thread: separate streams of execution that share the same address space Process!= Thread One process can have multiple threads Threads communicate more efficiently More on thread later

Why use processes? General principle of divide and conquer Decompose a large problem into smaller ones easier to think well contained smaller problems Systems have many concurrent jobs going on E.g. Multiple users running multiple shells, I/O, OS must manage Easier to reason about processes than threads Sequential activities with well defined interactions

What is a process? Outline Process dispatching Common process operations Inter-process Communication

System categorization Uniprogramming: one process at a time Eg., early main frame systems, MSDOS Good: simple Bad: poor resource utilization, inconvenient for users Multiprogramming: multiple processes, when one waits, switch to another E.g, modern OS Good: increase resource utilization and user convenience Bad: complex Note: multiprogramming!= multiprocessing

Multiprogramming OS requirements for multiprogramming Scheduling: what process to run? (later) Dispatching: how to switch process? (today) Memory protection: how to protect process from one another? (later) Separation of policy and mechanism Recurring theme in OS Policy: decision making with some performance metric and workload (scheduling) Mechanism: low-level code to implement decisions (dispatching)

Process dispatching mechanism OS dispatching loop: while(1) { } run process for a while; Q1: how to gain control? save process state; next process = schedule (ready processes); load next process state; Q3: where to find processes? Q2: what state must be saved?

Q1: How does Dispatcher gain control? Must switch from user mode to kernel mode Cooperative multitasking: processes voluntarily yield control back to OS When: system calls that relinquish CPU Why bad: OS trusts user processes! True multitasking: OS preempts processes by periodic alarms Processes are assigned time slices Dispatcher counts timer interrupts before context switch Why good: OS trusts no one!

Q2: What state must be saved? Dispatcher stores process state in Process Control Block (PCB) What goes into PCB? Process state (running, ready ) Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

CPU Switch From Process to Process

Context switch Implementation: machine dependent Tricky: OS must save state w/o changing state! Need to save all registers to PCB in memory Run code to save registers, but code changes registers Solution: hardware support Performance? Can take long. A lot of stuff to save and restore. The time needed is hardware dependent Context switch time is pure overhead: the system does no useful work while switching Must balance context switch frequency with scheduling requirement

Q3: where to find processes? Data structure: process scheduling queues Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues when their states change

Process state diagram Process state New: being created Ready: waiting to be assigned a CPU Running: instructions are running on CPU Waiting: waiting for some event (e.g. IO) Terminated: finished

What is a process? Outline Process dispatching Common process operations Inter-process Communication

Process creation Option 1: from scratch (e.g, Win32 CreateProcess()) Load code and data into memory Create and initialize PCB (make it like saved from context switch) Add new PCB to ready queue Option 2: cloning (e.g., Unix fork(), exec()) Pause current process and save its state Copy its PCB (can select what to copy) Add new PCB to ready queue Anything else? Must distinguish parent and child

Process termination Normal: exit(int status) OS passes exit status to parent via wait(int *status) OS frees process resources Abnormal: kill(pid_t pid, int sig) OS can kill process Process can kill process

Zombie and orphan What if child exits before parent? Child becomes zombie Need to store exit status OS can t fully free Parent must call wait() to reap child What if parent exits before child? Child becomes orphan Need some process to query exit status Re-parent to process 1, the init process

What is a process? Outline Process dispatching Common process operations Inter-process Communication

Cooperating Processes Independent process cannot affect or be affected by the execution of another process. Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity/Convenience

Interprocess Communication Models Message Passing Shared Memory

Message Passing v.s. Shared Memory Message passing Why good? All sharing is explicit less chance for error Why bad? Overhead. Data copying, cross protection domains Shared Memory Why good? Performance. Set up shared memory once, then access w/o crossing protection domains Why bad? Things change behind your back error prone

Signals IPC Example: Unix signals A very short message: just a small integer A fixed set of available signals. Examples: 9: kill 11: segmentation fault Installing a handler for a signal sighandler_t signal(int signum, sighandler_t handler); Send a signal to a process kill(pid_t pid, int sig)

IPC Example: Unix pipe int pipe(int fds[2]) Creates a one way communication channel fds[2] is used to return two file descriptors Bytes written to fds[1] will be read from fds[0] int pipefd[2]; pipe(pipefd); switch(pid=fork()) { case -1: perror("fork"); exit(1); case 0: close(pipefd[0]); // write to fd 1 break; default: close(pipefd[1]); // read from fd 0 break; }

IPC Example: Unix Shared Memory int shmget(key_t key, size_t size, int shmflg); Create a shared memory segment key: unique identifier of a shared memory segment, or IPC_PRIVATE int shmat(int shmid, const void *addr, int flg) Attach shared memory segment to address space of the calling process shmid: id returned by shmget() int shmdt(const void *shmaddr); Detach from shared memory Problem: synchronization! (later)

Process in Linux Next lecture