Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored

Similar documents
Computer Systems Laboratory Sungkyunkwan University

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Total Score is updated. The score of PA4 will be changed! Please check it. Will be changed

Concurrent Programming

Concurrent Programming

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Concurrent Programming

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

Iterative Servers The course that gives CMU its Zip! Iterative servers process one request at a time. Concurrent Servers

Lecture #23 Concurrent Programming

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Concurrent Servers Dec 2, 2009"

Concurrent Programming April 21, 2005

Concurrent Programming

CONCURRENT PROGRAMMING. Lecture 5

Concurrent Programming

Three Basic Mechanisms for Creating Concurrent Flows. Systemprogrammering 2009 Föreläsning 10 Concurrent Servers. Process-Based Concurrent Server

Concurrent Programming

Concurrent Programming November 28, 2007

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Concurrent programming

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction!

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Contents. PA1 review and introduction to PA2. IPC (Inter-Process Communication) Exercise. I/O redirection Pipes FIFOs

Concurrent Programming

ECE 650 Systems Programming & Engineering. Spring 2018

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

Concurrent Programming

socketservertcl a Tcl extension for using SCM_RIGHTS By Shannon Noe - FlightAware

Multitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider

Experiential Learning Workshop on Basics of Socket Programming

Introduction to Client-Server Model

Semester 2, Computer Communication 352 Module 4

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 5. TCP Client-Server

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

Concurrent Programming

Network Programming November 3, 2008

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Approaches to Concurrency

Announcement (1) sys.skku.edu is now available

Εργαστήριο 9 I/O Multiplexing

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Light-Weight Processes: Dissecting Linux Threads

Operating System Structure

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

Socket Programming TCP UDP

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Piotr Mielecki Ph. D.

Killing Zombies, Working, Sleeping, and Spawning Children

CSE 153 Design of Operating Systems Fall 2018

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

9/13/2007. Motivations for Sockets What s in a Socket? Working g with Sockets Concurrent Network Applications Software Engineering for Project 1

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Signal Example 1. Signal Example 2

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

Project 2-1 User Programs

CSE 421/521 - Operating Systems Fall 2011 Recitations. Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar. Presented by...

User Programs. Computer Systems Laboratory Sungkyunkwan University

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Network Programming / : Introduc2on to Computer Systems 21 st Lecture, April. 4, Instructors: Todd Mowry and Anthony Rowe

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CISC2200 Threads Spring 2015

Client Server Computing

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

All the scoring jobs will be done by script

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Concurrent Programming

Contents. NOTICE & Programming Assignment 0 review. What will be next project? File IO & File IO exercise

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

CSC209 Review. Yeah! We made it!

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

UNIX Network Programming. Overview of Socket API Network Programming Basics

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

Workshop on Inter Process Communication Solutions

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

Example Questions for Midterm EE122, Fall 2008 EECS Berkeley

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Systems programming and Operating systems, 2005 Tentamen

Assignment 1. Teaching Assistant: Michalis Pachilakis (

Inter-process communication (IPC)

Part Two - Process Management. Chapter 3: Processes

Processes: Introduction. CS 241 February 13, 2012

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Transcription:

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class Not submitted Not scored 1

Concurrent Programming Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Sanghoon Han(sanghoon.han@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

Echo Server Revisited int main (int argc, char *argv[]) {... listenfd = socket(af_inet, SOCK_STREAM, 0); bzero((char *)&saddr, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(inaddr_any); saddr.sin_port = htons(port); bind(listenfd, (struct sockaddr *)&saddr, sizeof(saddr)); listen(listenfd, 5); while (1) { connfd = accept(listenfd, (struct sockaddr *)&caddr, &clen); while ((n = read(connfd, buf, MAXLINE)) > 0) { printf ("got %d bytes from client.\n", n); write(connfd, buf, n); close(connfd); 3

Iterative Servers (1) One request at a time client 1 server client 2 call connect ret connect call read ret read close call accept ret accept write close call accept ret accept write close call connect ret connect call read ret read close 4

Iterative Servers (2) Fundamental flaw call connect ret connect call fgets User goes out to lunch Client 1 blocks waiting for user to type in data client 1 server client 2 Server blocks waiting for data from Client 1 call accept ret accept call read Solution: use concurrent servers instead Use multiple concurrent flows to serve multiple clients at the same time. call connect Client 2 blocks waiting to complete its connection request until after lunch! 5

Creating Concurrent Flows Processes Kernel automatically interleaves multiple logical flows. Each flow has its own private address space. Threads Kernel automatically interleaves multiple logical flows. Each flow shares the same address space. Hybrid of processes and I/O multiplexing I/O multiplexing with select() User manually interleaves multiple logical flows Each flow shares the same address space Popular for high-performance server designs. 6

Exercise #1 With your own code, make echo server At server side, print the number of characters that received from client At client side, print the string that client typed 7

Concurrent Programming Process-based

Process-based Servers client 1 server client 2 call accept call connect call connect ret connect call fgets User goes out to lunch Client 1 blocks waiting for user to type in data call read child 1 fork... ret accept fork call accept ret accept child 2 call read write close ret connect call fgets write call read end read close 9

Implementation Issues Servers should restart accept() if it is interrupted by a transfer of control to the SIGCHLD handler Not necessary for systems with POSIX signal handling. Required for portability on some older Unix systems. Server must reap zombie children to avoid fatal memory leak Server must close its copy of connfd. Kernel keeps reference for each socket. After fork(), refcnt(connfd) = 2 Connection will not be closed until refcnt(connfd) = 0 10

Exercise #2 With your own code, make process-based echo server At the same time, multiple client can be served by echo server There should be no memory leakage There should be some codes that handle zombie process How about closing files? 11

Process-based Designs Pros Handles multiple connections concurrently. Clean sharing model. Descriptors (no), file tables (yes), global variables (no) Simple and straightforward. Cons Additional overhead for process control. Process creation and termination Process switching Nontrivial to share data between processes. Requires IPC (InterProcess Communication) mechanisms: FIFO s, System V shared memory and semaphores 12

Echo Server Iterative version int main (int argc, char *argv[]) {... while (1) { connfd = accept (listenfd, (struct sockaddr *)&caddr, &caddrlen)); while ((n = read(connfd, buf, MAXLINE)) > 0) { printf ("got %d bytes from client.\n", n); write(connfd, buf, n); close(connfd); 13

Echo Server: Process-based int main (int argc, char *argv[]) {... signal (SIGCHLD, handler); while (1) { connfd = accept (listenfd, (struct sockaddr *)&caddr, &caddrlen)); if (fork() == 0) { close(listenfd); while ((n = read(connfd, buf, MAXLINE)) > 0) { printf ("got %d bytes from client.\n", n); write(connfd, buf, n); close(connfd); exit(0); close(connfd); void handler(int sig) { pid_t pid; int stat; while ((pid = waitpid(-1, &stat, WNOHANG)) > 0); return; 14