ECE 297 Concurrent Servers Process, fork & threads ECE 297.

Slides:



Advertisements
Similar presentations
1 Processes Professor Jennifer Rexford
Advertisements

1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Understand Process concept Process scheduling Creating.
Processes CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CMPT 300: Operating Systems I Ch 3: Processes Dr. Mohamed Hefeeda
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
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
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
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.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Operating Systems Chapter 2
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.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
OS, , Part II Processes Department of Computer Engineering, PSUWannarat Suntiamorntut.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
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.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Threads. Readings r Silberschatz et al : Chapter 4.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Lecture 3 Process.
Processes and threads.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Operating System Concepts
Process Management Presented By Aditya Gupta Assistant Professor
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Chapter 3: Processes.
Lecture 2: Processes Part 1
CS 143A Quiz 1 Solution.
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
Processes Hank Levy 1.
Chapter 3: Processes.
Processes in Unix and Windows
CS510 Operating System Foundations
Processes Hank Levy 1.
Chapter 3: Process Management
Presentation transcript:

ECE 297 Concurrent Servers Process, fork & threads ECE 297

Our transaction bracket Repeat get(table, key, &r) Updates to r’s values based on application logic set(table, key, r) Until No ERR_Transaction_ABORT

Updating versioned records in the server Receives a set(table, key, r) message Check r’s version against the version stored If there is a mismatch –Return with Transaction Abort Error Otherwise –Perform the update By incrementing the version & storing –Return success In the server

Our transaction bracket Repeat get(table, key, &r) Updates to r’s values based on application logic set(table, key, r) Until No ERR_Transaction_ABORT Do you see a problem with this approach to process transactions?

Problem After the get and before the set, the application could accidentally modify the version (or maliciously do so) Maybe update version to the version a concurrent update sequence modifies the version to Do you see a solution? –This is something to discuss in your design documents

ECE 297 Concurrent Servers Process, fork & threads ECE 297

Agenda Background on processes Creating processes (fork()) Concurrent server with fork() Background on threads Concurrent servers with threads

ECE 297 Background on processes

ECE 297 Process examples Your browser Your reader The shell your are working in Compiler, debugger, Eclipse Word PowerPoint Your application (i.e., test cases) Your storage server, its client(s) Background

ECE 297 Operating system process definitions A process is a program in execution A unit of execution characterized by –A single, sequential thread of execution –A current state (registers, program counter, …) –An associated set of system resources (memory, devices, files) A unit of resource ownership (more general) In the OS processes are identified with unique IDs (process identifiers ( PID )) Sometimes also referred to as job, task, activity, … Background

ECE 297 Process structure A process consists of 1. An executable (i.e., code) 2. Associated data needed by the program (global data, dynamic data, shared data) 3. Execution context (or state) of the program, e.g., - Contents of data registers - Program counter, stack pointer - Memory allocation - Open file (file descriptors) code stack dynamic data data Memory Background

ECE 297 Process context (state) & Process Control Block Program counter CPU registers CPU scheduling information Memory management information Accounting information I/O status information Background OS manages processes as queues of PCBs

ECE 297 Context switch CPU switching from one process to another process is called a context switch. Execution state of running process has to be saved and execution state of next process has to be loaded (context is switched.). Time to save old and load new processes’ execution state is called context-switch time. This time is overhead ; The system does no useful work while switching. Needs to be small. Time depends on hardware support. Background

ECE 297 Concurrency Apparent, simultaneous execution of multiple different processes in an interleaved fashion The context switching among processes creates the illusion of processes running at the same time Given multiple cores or processors, processes may truly run in parallel Background

ECE 297 Process creation

ECE 297 Process Creation Parent processes create child processes, which in turn may create other child processes forming a tree of processes in the system –pid_t fork(void) Typically, child processes inherit parent’s resources (code, address space, memory, file descriptors etc.) –i.e., child is a duplicate of parent Sadly, but truly each child has one parent only,  Each parent may have many children If a parent dies, its children are inherited by the init process (a process created by the OS shortly after boot)

ECE 297 … i = fork() … A process

ECE 297 … i = fork() … Parent process … i = fork() … Child process Parent and child are concurrently running processes Program Counter Program Counter i = Process ID of child i = 0 !

ECE 297 Concurrent server

ECE 297 listenfd = socket(AF_INET, SOCK_STREAM, 0) … bind(listenfd, …) listen(listenfd, …) for( ; ; ){ … connfd = accept(listenfd, …); … if ( (childPID = fork()) == 0 ){ // The Child! close(listenfd); // Close listening socket do the work // Process the request exit(0); } … close(connfd); // Parent closes connfd } Concurrent server template

ECE 297 if ( ( childPID = fork() ) == 0 ){ this code does not execute } Child process Parent process if ( ( childPID = fork() ) == 0 ){ this code executes! }

ECE 297 Status of client & server I

ECE 297 listenfd = socket(AF_INET, SOCK_STREAM, 0) … bind(listenfd, …) listen(listenfd, …) for( ; ; ){ … connfd = accept(listenfd, …); … if ( (childPID = fork()) == 0 ){ // The Child! close(listenfd); // Close listening socket do the work // Process the request exit(0); } … close(connfd); // Parent closes connfd }

ECE 297 Status of client & server II

ECE 297 listenfd = socket(AF_INET, SOCK_STREAM, 0) … bind(listenfd, …) listen(listenfd, …) for( ; ; ){ … connfd = accept(listenfd, …); … if ( (childPID = fork()) == 0 ){ // The Child! close(listenfd); // Close listening socket do the work // Process the request exit(0); } … close(connfd); // Parent closes connfd }

ECE 297 Status of client & server III

ECE 297 listenfd = socket(AF_INET, SOCK_STREAM, 0) … bind(listenfd, …) listen(listenfd, …) for( ; ; ){ … connfd = accept(listenfd, …); … if ( (childPID = fork()) == 0 ){// The Child! close(listenfd); //Close listening socket do the work //Process the request exit(0); } … close(connfd); //Parent closes connfd } Concurrent server template

ECE 297 Concurrent server with fork() Basically, the template suffices to complete Milestone 4’s concurrency requirement based on process-based concurrent server Do consider caching and file access complications There are a few more complications –Zombie children –Signals –Interrupted system calls (on some OSes)

ECE 297 Pros & cons of fork()-based design Handles multiple connections concurrently Clean sharing model –File/socket descriptors are shared –Global variables are not shared They are carbon copies! Simple and straightforward

ECE 297 Pros & cons of fork()-based design Non-trivial to share data between processes Requires inter-process communication mechanisms (IPC) sockets shared memory semaphores Heavy overhead for process management (creation)