NETWORK PROGRAMMING. Ipv4 and Ipv6 interoperability

Size: px
Start display at page:

Download "NETWORK PROGRAMMING. Ipv4 and Ipv6 interoperability"

Transcription

1 NETWORK PROGRAMMING UNIT V ADVANCED SOCKETS Ipv4 and Ipv6 interoperability threaded servers thread creation and termination TCP echo server using threads Mutexes condition variables raw sockets raw socket creation raw socket output raw socket input ping program trace route program. Ipv4 and Ipv6 interoperability Server and client combination IPv4 <=> IPv4(most server and client) IPv4 <=> IPv6 IPv6 <=> IPv4 IPv6 <=> IPv6 How IPv4 application and IPv6 application can communicate with each other. Hosts are running dual stacks, both an IPv4 protocol stack and IPv6 protocol stack. IPv4 Client, IPv6 Server IPv6 dual stack server can handle both IPv4 and IPv6 clients. This is done using IPv4-mapped IPv6 address server create an IPv6 listening socket that is bound to the IPv6 wildcard address. 1 CCET

2 IPv6 client, IPv4 server IPv4 server start on an IPv4 only host and create an IPv4 listening socket IPv6 client start, call gethostbyname. IPv4 mapped IPv6 address is returnedusing IPv4 datagram. Converting an IPv4 to IPv6 2 CCET

3 Int af; socklen_t clilen; struct sockaddr_int6 cli; /* IPv6 struct */ struct hostent *ptr; af = AF_INT6; Setsockopt (STDIN_FILENO, IPPROTO_IPV6, IPV6_ADDRFORM, &af, sizeof(af)); clilen = sizeof (cli); Getpeername(0, &cli, &clilen); ptr = gethostbyaddr (&cli.sin6_addr, 16, AF_INET); setsockopt => change the Address format of socket from IPv4 to IPv6. Return value is AF_INET or AF_INET6 getpeername =>return an IPv4-mapped IPv6 address Threaded Servers Thread A thread is not an object A thread is a flow of control A thread is a series of executed statements A thread is a nested sequence of method calls The Thread Object A thread is not an object A Thread is an object void start() Creates a new thread and makes it runnable void run() The new thread begins its life inside this method Runnable Interface A helper to the thread object The Thread object s run() method calls the Runnable object s run() method Allows threads to run inside any object, regardless of inheritance Runnable Example Talker talker = new Talker(); Thread t = new Thread(talker); t.start(); 3 CCET

4 --- class Talker implements Runnable { public void run() { while (true) { System.out.println( yakitty yak ); Blocking Threads When reading from a stream, if input is not available, the thread will block Thread is suspended ( blocked ) until I/O is available Allows other threads to automatically activate When I/O available, thread wakes back up again Becomes runnable Not to be confused with the Runnable interface Thread Scheduling In general, the runnable thread with the highest priority is active (running) Java is priority-preemptive If a high-priority thread wakes up, and a low-priority thread is running Then the high-priority thread gets to run immediately Allows on-demand processing Efficient use of CPU Thread Starvation If a high priority thread never blocks Then all other threads will starve Must be clever about thread priority Thread Priorities: General Strategies Threads that have more to do should get lower priority Counterintuitive Cut to head of line for short tasks Give your I/O-bound threads high priority Wake up, immediately process data, go back to waiting for I/O Race Conditions Two threads are simultaneously modifying a single object Both threads race to store their value 4 CCET

5 In the end, the last one there wins the race (Actually, both lose) Race Condition Example class Account { int balance; public void deposit(int val) { int newbal; newbal = balance + val; balance = newbal; Thread Synchronization Language keyword: synchronized Takes out a monitor lock on an object Exclusive lock for that thread If lock is currently unavailable, thread will block Protects access to code, not to data Make data members private Synchronize accessor methods Puts a force field around the locked object so no other threads can enter Actually, it only blocks access to other synchronizing threads A rogue thread can "sneak in" and modify a variable it has access to Synchronization Example class Account { private int balance; synchronized public void deposit(int val) { int newbal; newbal = balance + val; balance = newbal; synchronized public void withdraw(int val) { int newbal; newbal = balance - val; 5 CCET

6 balance = newbal; Multithreaded Servers same thread accepts connect requests, then processes uses a forever loop Single thread here sufficient, quick response possible Longer task would cause backlog of client requests Each iteration of the processing loop will: accept connection request create a handler thread for that client server thread immediately returns to top of processing loop for( ; ; ) { Socket sessionsocket = myserversocket.accept(); // create new thread for service using // sessionsocket // start the thread Multithreaded Echo Server Server will read lines of text client sends echo back each line may be multiple lines, time consuming EchoServer class builds its ServerSocket repeatedly invokes accept() creates new EchoHandler thread for each request Thread Creation and Termination Thread Creation Diagram 6 CCET

7 Threads creation Nearly all Linux distributions have thread frameworks e.g. POSIX (widely used standard in thread programming), called pthread. Include of required header file: #include <pthread.h> Compilation against Pthread library: gcc lpthread <source> Debugging tools like gdb or ddd support threads as well. Before creating a thread: write or at least declare a tread function declare a thread handle (data type: pthread_t) and prepare the attribute of this thread: data type for the attribute: pthread_attr_t detach state (PTHREAD_CREATE_JOINABLE, PTHREAD_CREATE_DETACHED) scheduling policy and schedule parameters stack size (size in bytes which is reserved for this thread in the stack) Example: void* thread_func(void* arg) { // do something int main() { pthread_t t_handle; 7 CCET

8 pthread_attr_t attr; int status; status = pthread_attr_init(&attr); status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); status = pthread_create(&t_handle, &attr, (void*) thread_func, NULL); status = pthread_attr_destroy(&attr); // do something else Access to application data inside thread function: thread function has same access to application resources (data, functions) like calling thread (main function) global variables or pointers (bad concurrency problems, if not protected) dedicated access functions (good, if concurrency protection implemented) called functions are duplicates (both, main and thread func, can call the same function at the same time, but they are not working on the same stack area) Threads termination A thread ends, when: main thread function finishes call of: void pthread_exit(void* exitval); inside thread function call of: int pthread_cancel(t_handle); outside of thread function Note: call of exit() in thread exits whole process Request of exit value of a thread: int pthread_join(t_handle, &exitval); but terminated thread must have been created with PTHREAD_JOINABLE as attribute. Can be used for synchronisation: waits for termination of thread t_handle 8 CCET

9 Figure 26.3 TCP echo server using threads (see also Exercise 26.5) Network Programming MC9241 A thread can declare its cancel state: enable PTHREAD_CANCEL_ENABLE disable PTHREAD_CANCEL_DISABLE int pthread_setcancelstate(int state, int *oldstate) And also the cancel type: immediate cancellation: PTHREAD_CANCEL_ASYNCHRONOUS cancellation at dedicated cancellation points: PTHREAD_CANCEL_DEFERRED int pthread_setcanceltype(int type, int *oldtype); Normally declared in beginning of thread, but can also be changed later on. Threads frameworks POSIX in most Linux distributions included ACE The ADAPTIVE Communication Environment TCP Echo server using Threads Create thread 9 CCET Thread function

10 Passing Arguments to New Threads Figure 26.4 TCP echo server using threads with more portable argument passing. 10 CCET

11 Mutexes Mutual Exclusion Consider the following scenario: Thread A is running and it loads the value of nconn (3) into a register. The system switches threads from A to B. A s registers are saved, and B s register are restored. Thread B executes the three instructions corresponding to the C expression nconn--, storing the new value of 2. Sometime later the system switches thread from A to A. A s register are restored and A continues where it left off, at the second machine instruction in the three-instructions sequence Solution Figure Two threads that increment a global variable incorrectly. o o o To protect the shared variable with a mutex and access the variable only when we hold the mutex. A mutex is a variable of type pthread_mutex_t. Two function of mutex lock and unlock 11 CCET

12 Control Variables A mutex is fine to prevent simultaneous access to a shared variable, but we need something else to let us go to sleep waiting for some condition to occur. We cannot call the Pthread function until we know that a thread has terminated o declare a global that counts the number of terminated threads and protect it with a mutex. The main loop never goes to sleep, and it checks ndone every time. This is called polling and is considered a waste of CPU time 12 CCET

13 Mutex and condition variables o Mutex : provides mutual exclusion o Condition variable : provides a signaling mechanism Other Functions pthread_cond_broadcast will wake up all threads that are blocked on the condition variable. pthread_cond_timewait lets a thread place a limit on how long it will block. 13 CCET

14 Raw Sockets Bypass TCP/UDP layers Read and write ICMP and IGMP packets o ping, traceroute, multicast daemon Read and write IP datagrams with an IP protocol field not processed by the kernel o OSPF o user process versus kernel Send and receive your own IP packets with your own IP header using the IP_HDRINCL socket option o can build and send TCP and UDP packets o testing, hacking o only superuser can create raw socket though You need to do all protocol processing at user-level 14 CCET

15 Creating a Raw Socket int sockfd; sockfd = socket(af_inet, SOCK_RAW, protocol); const int on = 1; setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on); Raw Socket Input. UDP / TCP Never pass to Raw Socket 2. Most ICMP Kernel => Raw Socket 3. All IGMP Kernel => Raw Socket 4. All Unknown IP Datagram Kernel ~> Raw Socket 5. Fragment In Reassemble ~> Raw Socket 15 CCET

16 Raw Socket Output 1. Sendto / sendmsg + destination IP connect => write / writev / send 2. Starting Address for the kernel to write Starting Addr. = First byte following the IP header Set IP_HDRINCL => Starting Addr. = First byte of the IP header 3. Fragmentation by kernel Sending raw socket packets by sendto or sendmsg o If IP_HDRINCL option not set (i.e. header is not included), the starting address of the data in sendto() specifies the first byte following the IP header o If IP_HDRINCL option set, the starting address of data in sendto() specifies the first byte of the IP header. o IP Header fields modified on sending by IP_HDRINCL o IP Checksum Always filled in. o Source Address Filled in when zero. o Packet Id Filled in when zero. o Total Length Always filled in. o Example: see Steven s code under ping/send_v4.c, ping/send_v6.c Scatter read and gather write Vectored IO struct iovec { void *iov_base; /* addr. Of buffer */ size_t iov_len; /* size of buffer */ Send and receive from one or more buffers with a single function call. 16 CCET

17 Ping Program Create a raw socket to send/receive ICMP echo request and echo reply packets Install SIGALRM handler to process output o Sending echo request packets every t second o Build ICMP packets (type, code, checksum, id, seq, sending timestamp as optional data) Enter an infinite loop processing input o Use recvmsg() to read from the network o Parse the message and retrieve the ICMP packet o Print ICMP packet information, e.g., peer IP address, round-trip time Source code: Steven s under ping/ Overview of Ping 17 CCET

18 Trace Route Program Create a UDP socket and bind source port o To send probe packets with increasing TTL o For each TTL value, use timer to send a probe every three seconds, and send 3 probes in total Create a raw socket to receive ICMP packets o If timeout, printing * o If ICMP port unreachable, then terminate o If ICMP TTL expired, then printing hostname of the router and round trip time to the router Source code: Steven s traceroute/ 18 CCET

19 Example of Traceroute Solaris # traceroute gemini.tuc.noao.edu traceroute to gemini.tuc.noao.edu ( ): 30 hops max, 12 data bytes 1 gw.kohala.com ( ) 3.839ms 3.595ms 3.722ms 2 tuc -1 -s1-9.rtd.net ( ) ms ms ms 3 frame -gw.ttn.ep.net ( ) ms ms ms... 7 gemini.tuc.noao.edu ( ) ms ms ms 19 CCET

IPv4 and ipv6 INTEROPERABILITY

IPv4 and ipv6 INTEROPERABILITY IT2351-NPM/UNIT-4/ 1 IPv4 and ipv6 INTEROPERABILITY Till the time, IPv6 is established all over the world, there is a need for one to host dual stacks that is both IPv4 and IPv6 are running concurrently

More information

Introduction! Overview! Signal-driven I/O for Sockets! Two different UDP servers!

Introduction! Overview! Signal-driven I/O for Sockets! Two different UDP servers! Overview Last Lecture Advanced UDP sockets and threads Source: Chapters 22&26 of Stevens book This Lecture Signal-driven I/O, Raw sockets Source: Chapters 25&28&29 of Stevens book Next Lecture WSN and

More information

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

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Slides based on the book Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne,

More information

UNIT IV- SOCKETS Part A

UNIT IV- SOCKETS Part A 1. Define sockets - SOCKETS Part A A socket is a construct to provide a communication between computers. It hides the underlying networking concepts and provides us with an interface to communicate between

More information

Lecture 4. Threads vs. Processes. fork() Threads. Pthreads. Threads in C. Thread Programming January 21, 2005

Lecture 4. Threads vs. Processes. fork() Threads. Pthreads. Threads in C. Thread Programming January 21, 2005 Threads vs. Processes Lecture 4 Thread Programming January 21, 2005 fork() is expensive (time, memory) Interprocess communication is hard. Threads are lightweight processes: one process can contain several

More information

POSIX Threads. Paolo Burgio

POSIX Threads. Paolo Burgio POSIX Threads Paolo Burgio paolo.burgio@unimore.it The POSIX IEEE standard Specifies an operating system interface similar to most UNIX systems It extends the C language with primitives that allows the

More information

User Space Multithreading. Computer Science, University of Warwick

User Space Multithreading. Computer Science, University of Warwick User Space Multithreading 1 Threads Thread short for thread of execution/control B efore create Global During create Global Data Data Executing Code Code Stack Stack Stack A fter create Global Data Executing

More information

CS 153 Lab4 and 5. Kishore Kumar Pusukuri. Kishore Kumar Pusukuri CS 153 Lab4 and 5

CS 153 Lab4 and 5. Kishore Kumar Pusukuri. Kishore Kumar Pusukuri CS 153 Lab4 and 5 CS 153 Lab4 and 5 Kishore Kumar Pusukuri Outline Introduction A thread is a straightforward concept : a single sequential flow of control. In traditional operating systems, each process has an address

More information

High Performance Computing Course Notes Shared Memory Parallel Programming

High Performance Computing Course Notes Shared Memory Parallel Programming High Performance Computing Course Notes 2009-2010 2010 Shared Memory Parallel Programming Techniques Multiprocessing User space multithreading Operating system-supported (or kernel) multithreading Distributed

More information

real time operating systems course

real time operating systems course real time operating systems course 4 introduction to POSIX pthread programming introduction thread creation, join, end thread scheduling thread cancellation semaphores thread mutexes and condition variables

More information

ANSI/IEEE POSIX Standard Thread management

ANSI/IEEE POSIX Standard Thread management Pthread Prof. Jinkyu Jeong( jinkyu@skku.edu) TA Jinhong Kim( jinhong.kim@csl.skku.edu) TA Seokha Shin(seokha.shin@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The

More information

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book! Lecture 5 Overview! Last Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book! This Lecture! Socket options! Source: Chapter 7 of Stevens book! Elementary UDP sockets! Source: Chapter 8 of Stevens

More information

NETWORK PROGRAMMING AND MANAGEMENT 1 KINGS DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK

NETWORK PROGRAMMING AND MANAGEMENT 1 KINGS DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK NETWORK PROGRAMMING AND MANAGEMENT 1 KINGS COLLEGE OF ENGINEERING DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK Subject Code & Name: Network Programming and Management Year / Sem : III / VI UNIT-

More information

1. Purpose. 2. Description Run-Time Issues Overview

1. Purpose. 2. Description Run-Time Issues Overview 1. Purpose CPS 470/570: Computer Networks Assignment 4, due 11:55 PM, 4-19-2017 Receive an F for this course if dishonesty occurs Receive 5 bonus points if submit it without errors one day before the deadline

More information

Contents. Part 1. Introduction and TCP/IP 1. Foreword Preface. xix. I ntroduction 31

Contents. Part 1. Introduction and TCP/IP 1. Foreword Preface. xix. I ntroduction 31 Foreword Preface Xvii xix Part 1. Introduction and TCP/IP 1 Chapter 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 Chapter 2. 2.1 2.2 2.3 I ntroduction I ntroduction 3 A Simple Daytime Client 6

More information

LESSON PLAN. Sub. Code & Name : IT2351 & Network Programming and Management Unit : I Branch: IT Year : III Semester: VI.

LESSON PLAN. Sub. Code & Name : IT2351 & Network Programming and Management Unit : I Branch: IT Year : III Semester: VI. Unit : I Branch: IT Year : III Semester: VI Page: 1 of 6 UNIT I ELEMENTARY TCP SOCKETS 9 Introduction to Socket Programming Overview of TCP/IP Protocols Introduction to Sockets Socket address Structures

More information

pthreads CS449 Fall 2017

pthreads CS449 Fall 2017 pthreads CS449 Fall 2017 POSIX Portable Operating System Interface Standard interface between OS and program UNIX-derived OSes mostly follow POSIX Linux, macos, Android, etc. Windows requires separate

More information

CSE 333 SECTION 9. Threads

CSE 333 SECTION 9. Threads CSE 333 SECTION 9 Threads HW4 How s HW4 going? Any Questions? Threads Sequential execution of a program. Contained within a process. Multiple threads can exist within the same process. Every process starts

More information

Threads. studykorner.org

Threads. studykorner.org Threads Thread Subpart of a process Basic unit of CPU utilization Smallest set of programmed instructions, can be managed independently by OS No independent existence (process dependent) Light Weight Process

More information

VALLIAMMAI ENGINEERING COLLEGE. SRM Nagar, Kattankulathur QUESTION BANK

VALLIAMMAI ENGINEERING COLLEGE. SRM Nagar, Kattankulathur QUESTION BANK SRM Nagar, Kattankulathur 603 203 IV SEMESTER MC7404 NETWORK PROGRAMMING Regulation 2013 Academic Year 2017 18 Prepared by Mr. M.Asan Nainar, Assistant Professor/MCA UNIT I - INTRODUCTION Overview of UNIX

More information

Table of Contents 1 System Maintaining and Debugging Commands 1-1

Table of Contents 1 System Maintaining and Debugging Commands 1-1 Table of Contents 1 System Maintaining and Debugging Commands 1-1 System Maintaining Commands 1-1 ping 1-1 tracert 1-4 System Debugging Commands 1-6 debugging 1-6 display debugging 1-7 i 1 System Maintaining

More information

Overview. Daemon processes and advanced I/O. Source: Chapters 13&14 of Stevens book

Overview. Daemon processes and advanced I/O. Source: Chapters 13&14 of Stevens book Overview Last Lecture Broadcast and multicast This Lecture Daemon processes and advanced I/O functions Source: Chapters 13&14 of Stevens book Next Lecture Unix domain protocols and non-blocking I/O Source:

More information

Elementary TCP Sockets

Elementary TCP Sockets Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens Distributed Computer Systems 1 socket interface Application 1 Application 2 socket interface user kernel user kernel

More information

CS 3305 Intro to Threads. Lecture 6

CS 3305 Intro to Threads. Lecture 6 CS 3305 Intro to Threads Lecture 6 Introduction Multiple applications run concurrently! This means that there are multiple processes running on a computer Introduction Applications often need to perform

More information

Pthreads. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Pthreads. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Pthreads Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Pthreads API ANSI/IEEE POSIX1003.1-1995 Standard Thread management Work directly on

More information

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή EPL372 Lab Exercise 2: Threads and pthreads Εργαστήριο 2 Πέτρος Παναγή 1 Threads Vs Processes 2 Process A process is created by the operating system, and requires a fair amount of "overhead". Processes

More information

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani Titolo presentazione Piattaforme Software per la Rete sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Outline 1) Introduction to Sockets 2) UDP communication 3) TCP communication 4) RAW

More information

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid.

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid. Threads Dr. Ayman Abdel-Hamid, CS4254 Spring 2006 1 CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department Virginia Tech Threads Outline Threads (Chapter

More information

(ICMP), RFC

(ICMP), RFC Internet et Control o Message Protocol (ICMP), RFC 792 http://icourse.cuc.edu.cn/networkprogramming/ linwei@cuc.edu.cn Nov. 2009 Overview The IP (Internet Protocol) relies on several other protocols to

More information

Introduction to PThreads and Basic Synchronization

Introduction to PThreads and Basic Synchronization Introduction to PThreads and Basic Synchronization Michael Jantz, Dr. Prasad Kulkarni Dr. Douglas Niehaus EECS 678 Pthreads Introduction Lab 1 Introduction In this lab, we will learn about some basic synchronization

More information

Table of Contents 1 System Maintenance and Debugging Commands 1-1

Table of Contents 1 System Maintenance and Debugging Commands 1-1 Table of Contents 1 System Maintenance and Debugging Commands 1-1 System Maintenance Commands 1-1 ping 1-1 ping ipv6 1-5 tracert 1-6 tracert ipv6 1-7 System Debugging Commands 1-8 debugging 1-8 display

More information

Processes and Threads

Processes and Threads TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Processes and Threads [SGG7] Chapters 3 and 4 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

Multithreaded Programming

Multithreaded Programming Multithreaded Programming The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. September 4, 2014 Topics Overview

More information

Concurrency, Thread. Dongkun Shin, SKKU

Concurrency, Thread. Dongkun Shin, SKKU Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point

More information

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags Outline SWE 545 Socket Options POSIX name/address conversion Out-of-Band Data Advanced Socket Programming 2 Socket Options Various attributes that are used to determine the behavior of sockets Setting

More information

CSCI4430 Data Communication and Computer Networks. Pthread Programming. ZHANG, Mi Jan. 26, 2017

CSCI4430 Data Communication and Computer Networks. Pthread Programming. ZHANG, Mi Jan. 26, 2017 CSCI4430 Data Communication and Computer Networks Pthread Programming ZHANG, Mi Jan. 26, 2017 Outline Introduction What is Multi-thread Programming Why to use Multi-thread Programming Basic Pthread Programming

More information

Thread and Synchronization

Thread and Synchronization Thread and Synchronization pthread Programming (Module 19) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014 Real-time Systems Lab, Computer Science and Engineering, ASU Pthread

More information

Programming with Shared Memory. Nguyễn Quang Hùng

Programming with Shared Memory. Nguyễn Quang Hùng Programming with Shared Memory Nguyễn Quang Hùng Outline Introduction Shared memory multiprocessors Constructs for specifying parallelism Creating concurrent processes Threads Sharing data Creating shared

More information

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF MCA QUESTION BANK UNIT 1

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF MCA QUESTION BANK UNIT 1 CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF MCA QUESTION BANK SUBJECT: NETWORK PROGRAMMING/MC9241 YEAR/ SEM: II /I V 1 CCET UNIT 1 1. What are the steps involved in obtaining a shared

More information

Threads. Threads (continued)

Threads. Threads (continued) Threads A thread is an alternative model of program execution A process creates a thread through a system call Thread operates within process context Use of threads effectively splits the process state

More information

POSIX Threads. HUJI Spring 2011

POSIX Threads. HUJI Spring 2011 POSIX Threads HUJI Spring 2011 Why Threads The primary motivation for using threads is to realize potential program performance gains and structuring. Overlapping CPU work with I/O. Priority/real-time

More information

Lecture 10 Overview!

Lecture 10 Overview! Lecture 10 Overview! Last Lecture! Wireless Sensor Networks! This Lecture! Daemon processes and advanced I/O functions! Source: Chapters 13 &14 of Stevens book! Next Lecture! Unix domain protocols and

More information

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process EECS 3221 Operating System Fundamentals What is thread? Thread Concept No. 3 Thread Difference between a process and a thread Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

More information

Introduction to pthreads

Introduction to pthreads CS 220: Introduction to Parallel Computing Introduction to pthreads Lecture 25 Threads In computing, a thread is the smallest schedulable unit of execution Your operating system has a scheduler that decides

More information

CS 345 Operating Systems. Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization

CS 345 Operating Systems. Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization CS 345 Operating Systems Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization Assignment 2 We have a treasure room, Team A and Team B. Treasure room has N coins inside. Each team

More information

Internet Control Message Protocol (ICMP)

Internet Control Message Protocol (ICMP) Internet Control Message Protocol (ICMP) 1 Overview The IP (Internet Protocol) relies on several other protocols to perform necessary control and routing functions: Control functions (ICMP) Multicast signaling

More information

Internet Control Message Protocol (ICMP), RFC 792. Prof. Lin Weiguo Copyleft 2009~2017, School of Computing, CUC

Internet Control Message Protocol (ICMP), RFC 792. Prof. Lin Weiguo Copyleft 2009~2017, School of Computing, CUC Internet Control Message Protocol (ICMP), RFC 79 Prof Lin Weiguo Copyleft 009~07, School of Computing, CUC Oct 07 Overview } The IP (Internet Protocol) relies on several other protocols to perform necessary

More information

Preview. What are Pthreads? The Thread ID. The Thread ID. The thread Creation. The thread Creation 10/25/2017

Preview. What are Pthreads? The Thread ID. The Thread ID. The thread Creation. The thread Creation 10/25/2017 Preview What are Pthreads? What is Pthreads The Thread ID The Thread Creation The thread Termination The pthread_join() function Mutex The pthread_cancel function The pthread_cleanup_push() function The

More information

CSCD433/533 Advanced Networks Winter 2017 Lecture 13. Raw vs. Cooked Sockets

CSCD433/533 Advanced Networks Winter 2017 Lecture 13. Raw vs. Cooked Sockets CSCD433/533 Advanced Networks Winter 2017 Lecture 13 Raw vs. Cooked Sockets Introduction Better Understand the Protocol Stack Use Raw Sockets So far, sockets in Java either TCP or UDP based In fact, Java

More information

Agenda. Process vs Thread. ! POSIX Threads Programming. Picture source:

Agenda. Process vs Thread. ! POSIX Threads Programming. Picture source: Agenda POSIX Threads Programming 1 Process vs Thread process thread Picture source: https://computing.llnl.gov/tutorials/pthreads/ 2 Shared Memory Model Picture source: https://computing.llnl.gov/tutorials/pthreads/

More information

CSCE 463/612: Networks and Distributed Processing Homework 4 (100 pts) Due date: 5/6/18

CSCE 463/612: Networks and Distributed Processing Homework 4 (100 pts) Due date: 5/6/18 CSCE 463/612: Networks and Distributed Processing Homework 4 (100 pts) Due date: 5/6/18 1. Purpose Implement a fast version of traceroute and learn about the topology of the Internet. 2. Description Traceroute

More information

Light & NOS. Dan Li Tsinghua University

Light & NOS. Dan Li Tsinghua University Light & NOS Dan Li Tsinghua University Performance gain The Power of DPDK As claimed: 80 CPU cycles per packet Significant gain compared with Kernel! What we care more How to leverage the performance gain

More information

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1 Thread Disclaimer: some slides are adopted from the book authors slides with permission 1 IPC Shared memory Recap share a memory region between processes read or write to the shared memory region fast

More information

CptS 360 (System Programming) Unit 17: Network IPC (Sockets)

CptS 360 (System Programming) Unit 17: Network IPC (Sockets) CptS 360 (System Programming) Unit 17: Network IPC (Sockets) Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2018 Motivation Processes need to talk to each other

More information

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science NETWORK PROGRAMMING CSC- 341 25 Instructor: Junaid Tariq, Lecturer, Department of Computer Science 26 9 Lecture Sockets as means for inter-process communication (IPC) application layer Client Process Socket

More information

Socket Programming for TCP and UDP

Socket Programming for TCP and UDP CSCI4430 Data Communication and Computer Networks Socket Programming for TCP and UDP ZHANG, Mi Jan. 19, 2017 Outline Socket Programming for TCP Introduction What is TCP What is socket TCP socket programming

More information

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff POSIX threads CS 241 February 17, 2012 Copyright University of Illinois CS 241 Staff 1 Recall: Why threads over processes? Creating a new process can be expensive Time A call into the operating system

More information

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems. Last Class: CPU Scheduling Pre-emptive versus non-preemptive schedulers Goals for Scheduling: Minimize average response time Maximize throughput Share CPU equally Other goals? Scheduling Algorithms: Selecting

More information

ECE 574 Cluster Computing Lecture 8

ECE 574 Cluster Computing Lecture 8 ECE 574 Cluster Computing Lecture 8 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 16 February 2017 Announcements Too many snow days Posted a video with HW#4 Review HW#5 will

More information

Problems of IP. Unreliable connectionless service. Cannot acquire status information from routers and other hosts

Problems of IP. Unreliable connectionless service. Cannot acquire status information from routers and other hosts Chapter 09 ICMP Problems of IP Unreliable connectionless service Best effort service IP datagrams are discarded If destination is not found If TTL becomes 0 If reassembly timer expires Cannot acquire status

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),

More information

Chapter 4 Threads. Images from Silberschatz 03/12/18. CS460 Pacific University 1

Chapter 4 Threads. Images from Silberschatz 03/12/18. CS460 Pacific University 1 Chapter 4 Threads Images from Silberschatz Pacific University 1 Threads Multiple lines of control inside one process What is shared? How many PCBs? Pacific University 2 Typical Usages Word Processor Web

More information

CISC2200 Threads Spring 2015

CISC2200 Threads Spring 2015 CISC2200 Threads Spring 2015 Process We learn the concept of process A program in execution A process owns some resources A process executes a program => execution state, PC, We learn that bash creates

More information

Multicore and Multiprocessor Systems: Part I

Multicore and Multiprocessor Systems: Part I Chapter 3 Multicore and Multiprocessor Systems: Part I Max Planck Institute Magdeburg Jens Saak, Scientific Computing II 44/337 Symmetric Multiprocessing Definition (Symmetric Multiprocessing (SMP)) The

More information

MPAC BENCHMARKING LIBRARY

MPAC BENCHMARKING LIBRARY MPAC BENCHMARKING LIBRARY Table of Contents Introduction 3 1 mpac.h 4 1.1 MPAC_SUCCESS 4 1.2 MPAC_FAILURE 4 1.3 MPAC_NULL 4 1.4 mpac_min 4 1.5 mpac_max 4 1.6 mpac_g 5 1.7 mpac_m 5 1.8 mpac_k 5 1.9 mpac_handle

More information

Configuring Routes on the ACE

Configuring Routes on the ACE CHAPTER2 This chapter describes how the ACE is considered a router hop in the network when it is in routed mode. In the Admin or user contexts, the ACE supports static routes only. The ACE supports up

More information

Concurrent Server Design Multiple- vs. Single-Thread

Concurrent Server Design Multiple- vs. Single-Thread Concurrent Server Design Multiple- vs. Single-Thread Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN NTUT, TAIWAN 1 Examples Using

More information

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection Review Preview Algorithms and Issues in Client Software Design Client Architecture Identifying the Location of a Parsing an Address Argument Looking Up a Domain Name Looking Up a Well-Known Port by Name

More information

TCSS 422: OPERATING SYSTEMS

TCSS 422: OPERATING SYSTEMS TCSS 422: OPERATING SYSTEMS OBJECTIVES Introduction to threads Concurrency: An Introduction Wes J. Lloyd Institute of Technology University of Washington - Tacoma Race condition Critical section Thread

More information

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

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits CS307 What is a thread? Threads A thread is a basic unit of CPU utilization contains a thread ID, a program counter, a register set, and a stack shares with other threads belonging to the same process

More information

EEC-484/584 Computer Networks

EEC-484/584 Computer Networks EEC-484/584 Computer Networks Lecture 15 wenbing@ieee.org (Lecture nodes are based on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Outline 2 Review of last lecture The network layer

More information

Lecture 19: Shared Memory & Synchronization

Lecture 19: Shared Memory & Synchronization Lecture 19: Shared Memory & Synchronization COMP 524 Programming Language Concepts Stephen Olivier April 16, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Forking int pid;

More information

POSIX PTHREADS PROGRAMMING

POSIX PTHREADS PROGRAMMING POSIX PTHREADS PROGRAMMING Download the exercise code at http://www-micrel.deis.unibo.it/~capotondi/pthreads.zip Alessandro Capotondi alessandro.capotondi(@)unibo.it Hardware Software Design of Embedded

More information

Creating Threads. Programming Details. COMP750 Distributed Systems

Creating Threads. Programming Details. COMP750 Distributed Systems Creating Threads Programming Details COMP750 Distributed Systems Thread and Process Creation Processes can be created on Unix systems in C or C++ using the fork() function. Threads can be created in C

More information

Each ICMP message contains three fields that define its purpose and provide a checksum. They are TYPE, CODE, and CHECKSUM fields.

Each ICMP message contains three fields that define its purpose and provide a checksum. They are TYPE, CODE, and CHECKSUM fields. IP address ICMP Each ICMP message contains three fields that define its purpose and provide a checksum. They are TYPE, CODE, and CHECKSUM fields. The TYPE field identifies the ICMP message, the CODE field

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution

More information

ENCM 501 Winter 2019 Assignment 9

ENCM 501 Winter 2019 Assignment 9 page 1 of 6 ENCM 501 Winter 2019 Assignment 9 Steve Norman Department of Electrical & Computer Engineering University of Calgary April 2019 Assignment instructions and other documents for ENCM 501 can

More information

CS-345 Operating Systems. Tutorial 2: Grocer-Client Threads, Shared Memory, Synchronization

CS-345 Operating Systems. Tutorial 2: Grocer-Client Threads, Shared Memory, Synchronization CS-345 Operating Systems Tutorial 2: Grocer-Client Threads, Shared Memory, Synchronization Threads A thread is a lightweight process A thread exists within a process and uses the process resources. It

More information

Network Programming TDC 561

Network Programming TDC 561 Network Programming TDC 561 Lecture # 6: Multithreaded Servers Dr. Ehab S. Al-Shaer School of Computer Science & Telecommunication DePaul University Chicago, IL 1 Introduction to Multithreaded Network

More information

LSN 13 Linux Concurrency Mechanisms

LSN 13 Linux Concurrency Mechanisms LSN 13 Linux Concurrency Mechanisms ECT362 Operating Systems Department of Engineering Technology LSN 13 Creating Processes fork() system call Returns PID of the child process created The new process is

More information

Threads. lightweight processes

Threads. lightweight processes Threads lightweight processes 1 Motivation Processes are expensive to create. It takes quite a bit of time to switch between processes Communication between processes must be done through an external kernel

More information

COSC 6374 Parallel Computation. Shared memory programming with POSIX Threads. Edgar Gabriel. Fall References

COSC 6374 Parallel Computation. Shared memory programming with POSIX Threads. Edgar Gabriel. Fall References COSC 6374 Parallel Computation Shared memory programming with POSIX Threads Fall 2012 References Some of the slides in this lecture is based on the following references: http://www.cobweb.ecn.purdue.edu/~eigenman/ece563/h

More information

Ping, tracert and system debugging commands

Ping, tracert and system debugging commands Contents Ping, tracert and system debugging commands 1 Ping and tracert commands 1 ping 1 ping ipv6 5 tracert 7 tracert ipv6 9 System debugging commands 10 debugging 10 display debugging 11 i Ping, tracert

More information

Unix. Threads & Concurrency. Erick Fredj Computer Science The Jerusalem College of Technology

Unix. Threads & Concurrency. Erick Fredj Computer Science The Jerusalem College of Technology Unix Threads & Concurrency Erick Fredj Computer Science The Jerusalem College of Technology 1 Threads Processes have the following components: an address space a collection of operating system state a

More information

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Threads Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3052: Introduction to Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu) Concurrency

More information

CSC Systems Programming Fall Lecture - XXIII Final Review. Tevfik Koşar. Louisiana State University

CSC Systems Programming Fall Lecture - XXIII Final Review. Tevfik Koşar. Louisiana State University CSC 4304 - Systems Programming Fall 2008 Lecture - XXIII Final Review Tevfik Koşar Louisiana State University December 4 th, 2008 1 Using make 2 Implicit Rules 3 Using Variables in Makefiles 4 Libraries

More information

Using make. Using Variables in Makefiles. Implicit Rules. Static vs Dynamic Libraries. Libraries. Tevfik Ko!ar

Using make. Using Variables in Makefiles. Implicit Rules. Static vs Dynamic Libraries. Libraries. Tevfik Ko!ar CSC 4304 - Systems Programming Fall 2008 Using make Lecture - XXIII Final Review Tevfik Ko!ar Louisiana State University December 4 th, 2008 1 2 Implicit Rules Using Variables in Makefiles 3 4 Libraries

More information

MARIA COLLEGE OF ENGINEERING AND TECHNOLOGY, ATTOOR DEPARTMENT OF INFORMATION TECHNOLOGY NETWORK PROGRAMMING MANAGEMENT 2 MARKS QUESTIONS & ANSWERS

MARIA COLLEGE OF ENGINEERING AND TECHNOLOGY, ATTOOR DEPARTMENT OF INFORMATION TECHNOLOGY NETWORK PROGRAMMING MANAGEMENT 2 MARKS QUESTIONS & ANSWERS MARIA COLLEGE OF ENGINEERING AND TECHNOLOGY, ATTOOR DEPARTMENT OF INFORMATION TECHNOLOGY NETWORK PROGRAMMING MANAGEMENT 2 MARKS QUESTIONS & ANSWERS 1. What is a socket? UNIT-I TWO MARKS A socket is a logical

More information

Shared Memory Programming Models III

Shared Memory Programming Models III Shared Memory Programming Models III Stefan Lang Interdisciplinary Center for Scientific Computing (IWR) University of Heidelberg INF 368, Room 532 D-69120 Heidelberg phone: 06221/54-8264 email: Stefan.Lang@iwr.uni-heidelberg.de

More information

Table of Contents 1 System Maintaining and Debugging 1-1

Table of Contents 1 System Maintaining and Debugging 1-1 Table of Contents 1 System Maintaining and Debugging 1-1 System Maintaining and Debugging 1-1 Ping 1-1 Introduction 1-1 Configuring Ping 1-1 Ping Configuration Example 1-2 Tracert 1-4 Introduction 1-4

More information

Introduction to Socket Programming

Introduction to Socket Programming UNIT II - ELEMENTARY TCP SOCKETS Introduction to Socket Programming Introduction to Sockets Socket address Structures Byte ordering functions address conversion functions Elementary TCP Sockets socket,

More information

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne Chapter 4: Threads Silberschatz, Galvin and Gagne Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Linux Threads 4.2 Silberschatz, Galvin and

More information

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012 Eike Ritter 1 Modified: October 16, 2012 Lecture 8: Operating Systems with C/C++ School of Computer Science, University of Birmingham, UK 1 Based on material by Matt Smart and Nick Blundell Outline 1 Concurrent

More information

Internet Protocol. Outline Introduction to Internet Protocol Header and address formats ICMP Tools CS 640 1

Internet Protocol. Outline Introduction to Internet Protocol Header and address formats ICMP Tools CS 640 1 Internet Protocol Outline Introduction to Internet Protocol Header and address formats ICMP Tools CS 640 1 Internet Protocol Runs on all hosts in the Internet and enables packets to be routed between systems

More information

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Multilevel Feedback Queues (MLFQ) Multilevel feedback queues use past behavior to predict the future and assign

More information

User Datagram Protocol

User Datagram Protocol Topics Transport Layer TCP s three-way handshake TCP s connection termination sequence TCP s TIME_WAIT state TCP and UDP buffering by the socket layer 2 Introduction UDP is a simple, unreliable datagram

More information

4. Concurrency via Threads

4. Concurrency via Threads CSC400 - Operating Systems 4. Concurrency via Threads J. Sumey Overview Multithreading Concept Background Implementations Thread States & Thread Switching Thread Operations Case Study: pthreads CSC400

More information

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?!

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?! Overview!! Last Lecture!! Daemon processes and advanced I/O functions!! This Lecture!! VPN, NAT, DHCP!! Source: Chapters 19&22 of Comer s book!! Unix domain protocols and non-blocking I/O!! Source: Chapters

More information

TRAM. STUN Traceroute. draft-martinsen-tram-stuntrace-00. March 2015 IETF 92. Authors: Pål-Erik Martinsen, Dan Wing Presenter : Pål-Erik Martinsen

TRAM. STUN Traceroute. draft-martinsen-tram-stuntrace-00. March 2015 IETF 92. Authors: Pål-Erik Martinsen, Dan Wing Presenter : Pål-Erik Martinsen TRAM STUN Traceroute March 2015 IETF 92 Authors: Pål-Erik Martinsen, Dan Wing Presenter : Pål-Erik Martinsen 1 Intellectual Property Rights Cisco has declared IPR (https://datatracker.ietf.org/ipr/2544)

More information

Chapter 10. Threads. OS Processes: Control and Resources. A process as managed by the operating system groups together:

Chapter 10. Threads. OS Processes: Control and Resources. A process as managed by the operating system groups together: SFWR ENG 3BB4 Software Design 3 Concurrent System Design 2 SFWR ENG 3BB4 Software Design 3 Concurrent System Design 10.11 13 OS Processes: Control and Resources Chapter 10 Threads A process as managed

More information