Concurrency and Processes CSE 333 Spring 2018

Slides:



Advertisements
Similar presentations
1 Processes Professor Jennifer Rexford
Advertisements

1 Processes and Pipes COS 217 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.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Process Concept An operating system executes a variety of programs
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
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,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
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.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Threads. Readings r Silberschatz et al : Chapter 4.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Lecture 3 Process.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
CS399 New Beginnings Jonathan Walpole.
Chapter 4: Multithreaded Programming
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process Concept
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Chapter 3: Processes.
Server-side Programming CSE 333 Spring 2018
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
Concurrency and Threads CSE 333 Spring 2018
ICS 143 Principles of Operating Systems
Client-side Networking CSE 333 Spring 2018
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
Jonathan Walpole Computer Science Portland State University
References Revisited CSE 333 Spring 2018
Chapter 3: Processes.
Concurrency: Threads CSE 333 Summer 2018
Concurrency: Processes CSE 333 Summer 2018
Processes in Unix, Linux, and Windows
CS510 Operating System Foundations
Concurrency: Processes CSE 333 Autumn 2018
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
EECE.4810/EECE.5730 Operating Systems
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Chapter 3: Process Concept
Chapter 4: Threads.
EECE.4810/EECE.5730 Operating Systems
Concurrency: Processes CSE 333 Winter 2019
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Concurrency and Processes CSE 333 Spring 2018 Instructor: Justin Hsia Teaching Assistants: Danny Allen Dennis Shao Eddie Huang Kevin Bi Jack Xu Matthew Neldam Michael Poulain Renshu Gu Robby Marver Waylon Huang Wei Lin

Administrivia hw4 due tomorrow (5/31) Submissions accepted until Sunday (6/3) Final is Tuesday (6/5), 12:30-2:20 pm, KNE 120 Review Session: Sunday (6/3), 4-6:30 pm, EEB 125 Two double-sided, handwritten sheets of notes allowed Topic list and past finals on Exams page on website

Outline searchserver Reference: CSPP, Chapter 12 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: CSPP, Chapter 12

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, 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 child 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

Concurrency 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

Peer Instruction Question What will happen when one of the grandchildren processes finishes? A. Zombie until grandparent exits B. Zombie until grandparent reaps C. Zombie until init reaps D. ZOMBIE FOREVER!!! E. We’re lost…

Concurrent with Processes See searchserver_processes/

Why 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

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

Aside: Thread Pools In real servers, we’d like to avoid overhead needed to create a new thread or process for every request 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