Concurrency: Processes CSE 333 Winter 2019

Slides:



Advertisements
Similar presentations
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Advertisements

1 Processes Professor Jennifer Rexford
Processes CSCI 444/544 Operating Systems Fall 2008.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Introduction to Processes CS Intoduction to Operating Systems.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
CS333 Intro to Operating Systems Jonathan Walpole.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Department of Computer Science and Software Engineering
Threads. Readings r Silberschatz et al : Chapter 4.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Operating Systems CMPSC 473
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
CS399 New Beginnings Jonathan Walpole.
Chapter 4: Multithreaded Programming
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process Concept
Chapter 3: Processes.
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
CS 143A Quiz 1 Solution.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
CSE 153 Design of Operating Systems Winter 2018
Chapter 3: Processes.
Course Wrap-Up CSE 333 Autumn 2018
Concurrency: Threads CSE 333 Summer 2018
Concurrency: Processes CSE 333 Summer 2018
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Concurrency and Processes CSE 333 Spring 2018
Concurrency: Threads CSE 333 Autumn 2018
Operating Systems: A Modern Perspective, Chapter 6
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Introduction to Concurrency CSE 333 Autumn 2018
CS510 Operating System Foundations
Concurrency: Processes CSE 333 Autumn 2018
Server-side Programming CSE 333 Winter 2019
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
EECE.4810/EECE.5730 Operating Systems
Course Wrap-Up CSE 333 Winter 2019
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Low-Level I/O – the POSIX Layer CSE 333 Winter 2019
Chapter 3: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Concurrency: Threads CSE 333 Winter 2019
Introduction to Concurrency CSE 333 Winter 2019
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Concurrency: Processes CSE 333 Winter 2019 Instructor: Hal Perkins Teaching Assistants: Alexey Beall Renshu Gu Harshita Neti David Porter Forrest Timour Soumya Vasisht Yifan Xu Sujie Zhou

Administrivia hw4 due Thur. night (Plus late days – max 2 – if you have them) Please fill out course evals while they are available Final exam Wed. 3/20, 2:30-4:20 Some review in sections Thur.; review Q&A Tue. 3/19, 4:30 Topic list and old finals on Exams page Summer final exams are 1 hour; regular quarters are usual 2 hours Lecture Wednesday: System calls, buffering, libraries & more (no slides – be here!)

Outline searchserver Sequential Concurrent via forking threads – pthread_create() Concurrent via forking processes – fork() Concurrent via non-blocking, event-driven I/O – select() We won’t get to this  Reference: Computer Systems: A Programmer’s Perspective, Chapter 12 (CSE 351 book)

Creating New Processes Creates a new process (the “child”) that is an exact clone* of the current process (the “parent”) *Everything is cloned except threads: variables, file descriptors, open sockets, the virtual address space (code, globals, heap, stack), etc. Primarily used in two patterns: Servers: fork a child to handle a connection Shells: fork a child that then exec’s a new program pid_t fork(void);

fork() and Address Spaces 0xFF…FF 0x00…00 OS kernel [protected] Stack Heap (malloc/free) Read/Write Segment .data, .bss Shared Libraries Read-Only Segment .text, .rodata A process executes within an address space Includes segments for different parts of memory Process tracks its current state using the stack pointer (SP) and program counter (PC) SP PC

fork() and Address Spaces OS kernel [protected] Stack Heap (malloc/free) Read/Write Segment .data, .bss Shared Libraries Read-Only Segment .text, .rodata SP PC OS kernel [protected] Stack Heap (malloc/free) Read/Write Segment .data, .bss Shared Libraries Read-Only Segment .text, .rodata SP PC Fork cause the OS to clone the address space The copies of the memory segments are (nearly) identical The new process has copies of the parent’s data, stack-allocated variables, open file descriptors, etc. fork() PARENT CHILD

fork() fork() has peculiar semantics OS The parent invokes fork() The OS clones the parent Both the parent and the child return from fork Parent receives child’s pid Child receives a 0 parent OS fork()

fork() fork() has peculiar semantics OS The parent invokes fork() The OS clones the parent Both the parent and the child return from fork Parent receives child’s pid Child receives a 0 parent child OS clone

fork() fork() has peculiar semantics See fork_example.cc OS The parent invokes fork() The OS clones the parent Both the parent and the child return from fork Parent receives child’s pid Child receives a 0 See fork_example.cc parent child OS child pid

Concurrent Server with Processes The parent process blocks on accept(), waiting for a new client to connect When a new connection arrives, the parent calls fork() to create a child process The child process handles that new connection and exit()’s when the connection terminates Remember that children become “zombies” after death Option A: Parent calls wait() to “reap” children Option B: Use a double-fork trick

Double-fork Trick server

Double-fork Trick client connect server accept()

Double-fork Trick client server server fork() child Because fork() copies file descriptors, child has connection to client, too.

Double-fork Trick client server fork() grandchild server server

Double-fork Trick client server server child exit()’s / parent wait()’s server

Double-fork Trick client server server parent closes its client connection server

Double-fork Trick client server server

Double-fork Trick client server server server client server fork() child server fork() grandchild exit() client server

Double-fork Trick client server server client server

Double-fork Trick client server client server client server server

Concurrent with Processes See searchserver_processes/

Whither Concurrent Processes? Advantages: Almost as simple to code as sequential In fact, most of the code is identical! Concurrent execution leads to better CPU, network utilization Disadvantages: Processes are heavyweight Relatively slow to fork Context switching latency is high Communication between processes is complicated

How Fast is fork()? See forklatency.cc ~ 0.25 ms per fork* ∴ maximum of (1000/0.25) = 4,000 connections/sec/core ~350 million connections/day/core This is fine for most servers Too slow for super-high-traffic front-line web services Facebook served ~ 750 billion page views per day in 2013! Would need 3-6k cores just to handle fork(), i.e. without doing any work for each connection *Past measurements are not indicative of future performance – depends on hardware, OS, software versions, …

How Fast is pthread_create()? See threadlatency.cc ~0.036 ms per thread creation* ~10x faster than fork() ∴ maximum of (1000/0.036) = 28,000 connections/sec ~2.4 billion connections/day/core Mush faster, but writing safe multithreaded code can be serious voodoo *Past measurements are not indicative of future performance – depends on hardware, OS, software versions, …, but will typically be an order of magnitude faster than fork()

Aside: Thread Pools In real servers, we’d like to avoid overhead needed to create a new thread or process for every request Idea: Thread Pools: Create a fixed set of worker threads or processes on server startup and put them in a queue When a request arrives, remove the first worker thread from the queue and assign it to handle the request When a worker is done, it places itself back on the queue and then sleeps until dequeued and handed a new request