Consider Letting inetd Launch Your Application. inetd daemon  Problems starting with /etc/rc(without inet daemon)  All the servers contains nearly identical.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
CS Lecture 4 Programming with Posix Threads and Java Threads George Mason University Fall 2009.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Threads. What do we have so far The basic unit of CPU utilization is a process. To run a program (a sequence of code), create a process. Processes are.
CS162B: POSIX Threads Jacob Chan. Objectives ▪ Review on fork() and exec() – Some issues on forking and exec-ing ▪ POSIX Threads ▪ Lab 8.
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
3.5 Interprocess Communication
Lecture 18 Threaded Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
Unix Network Programming Chapter 13: Daemon processes and the inetd superserver Jani Peusaari.
Threads CSCI 444/544 Operating Systems Fall 2008.
Daemon Processes and inetd Superserver
Client Server Design Alternatives© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Netprog Threads Programming1 Threads Programming Refs: Chapter 23.
Assignment 3 A Client/Server Application: Chatroom.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Today’s topic Pthread Some materials and figures are obtained from the POSIX threads Programming tutorial at
June-Hyun, Moon Computer Communications LAB., Kwangwoon University Chapter 26 - Threads.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
POSIX Threads Programming Operating Systems. Processes and Threads In shared memory multiprocessor architectures, such as SMPs, threads can be used to.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
TELE 402 Lecture 10: Unix domain … 1 Overview Last Lecture –Daemon processes and advanced I/O functions This Lecture –Unix domain protocols and non-blocking.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
1 Unix Domain Protocols when client and server are on the same host Unix domain socket address structure Socket functions Stream client-server Datagram.
System calls for Process management
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Threads CSCE Thread Motivation Processes are expensive to create. Context switch between processes is expensive Communication between processes.
S -1 Posix Threads. S -2 Thread Concepts Threads are "lightweight processes" –10 to 100 times faster than fork() Threads share: –process instructions,
Threads and Locking Ioctl operations. Threads Lightweight processes What’s wrong with processes? –fork() is expensive – 10 to 100 times slower –Inter.
Threads Chapter 26. Threads Light-weight processes Each process can have multiple threads of concurrent control. What’s wrong with processes? fork() is.
1 Pthread Programming CIS450 Winter 2003 Professor Jinhua Guo.
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
CS 838: Pervasive Parallelism Introduction to pthreads Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
UNIX Network Programming1 Chapter 12. Daemon Processes and inetd Superserver.
NCHU System & Network Lab Lab #6 Thread Management Operating System Lab.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Thread Basic Thread operations include thread creation, termination, synchronization, data management Threads in the same process share:  Process address.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Operating Systems Review ENCE 360.
Threads Threads.
Netprog: Threads Programming
Linux Processes & Threads
Multithreading Tutorial
Threads and Cooperation
CGS 3763 Operating Systems Concepts Spring 2013
Advanced Network Programming spring 2007
Multithreading Tutorial
Unix System Calls and Posix Threads
Issues in Client/Server Programming
Multithreading Tutorial
Multithreading Tutorial
Daemons & inetd Refs: Chapter 12.
POSIX Threads(pthreads)
Presentation transcript:

Consider Letting inetd Launch Your Application

inetd daemon  Problems starting with /etc/rc(without inet daemon)  All the servers contains nearly identical startup code  Each daemon takes a slot in process table, but asleep most of time  /etc/inetd.conf file specifies the services that the superserver inetd is to handle

Steps performed by inetd dup2(sockfd, 0); dup2(sockfd, 1); dup2(sockfd, 2); close(sockfd); Open descriptor 들은 fork 시 copy 되고 Exec 후에도 유지된다. Exec 후에 Peer 를 알 수 있는 방법은 ?

Consider Using Two TCP Connections

Concurrent Input/Output processes  One-connection architecture  Xout 에서 send 할 때 pending error 는 xin 에서 recv 해야 알 수 있다  Xin  mp  xout 으로 알려 줘야 함  Two connection architecture  별도의 connection 에 대해 socket pending error 가 있는지 testing 가능  Using select() readability

Example xout1.c:

Interprocess Communication via UNIX Domain Protocols

UNIX Domain Sockets  A UNIX IPC method  Absolute pathname is used instead of protocol address and port number  Stream socket: similar to TCP socket  Datagram socket: similar to UDP socket  An unreliable datagram service that preserves record boundary may be discarded (receiver 가 빨리 읽어내지 못하면 ) may be discarded (receiver 가 빨리 읽어내지 못하면 )  Normally, used for passing descriptor  Usage of UNIX domain socket  Twice as fast as a TCP socket on the same host  Used when passing descriptors between processes on the same host (using sendmsg(), recvmsg());  Provides client’s credentials (UID, GID) to the server

UNIX Domain Stream Client/Server unixdomain/unixstrcli01.c unixdomain/unixstrserv01.c UNP

UNIX Domain Datagram Protocol unixdomai/unixdgcli01.c unixdomai/unixdgserv01.c Binding client address (pathname) is necessary to identify client UNP

Threads

Introduction  Process  Overhead in process creation(fork)  memory is copied  all descriptor are duplicated  IPC required to pass information between parent and child processes after fork  Thread: light-weight process  All threads within a process share the same global memory  raises synchronization and mutual exclusion problems  times faster than process creation  Many different thread implementation  Pthread: Posix thread

Shared and Own data in Threads  Shared information  process instructions  most data  open files (e.g., descriptor)  signal handlers and signal dispositions  current working directory  user and group IDs  Thread’s own data  thread ID  set of registers  stack  errno  signal masks  priority

Thread Creation and Termination  Thread attributes  priority  initial stack size  daemon thread or not: detached or joinable thread  default: NULL  Terminating a thread  implicit termination  when thread starting function returns  explicit termination  pthread_exit  exit

A Simpler Version of str_cli using Threads UNP

TCP Echo Server using Threads threads/tcpserv01.c threads/tcpserv02.c – more portable UNP

Non-determinism causes time-dependent errors  Non-determinism (Race Condition)  in C int ndone = 0; /* shared variable */ Thread A: Thread B: ndone++;done--;  Compiled output (ASM) LOAD ndone INCR LOAD ndone DECR STORE ndone  Result ??  An instruction is atomic (indivisible), but a statement may be divisible !!  Shared variables should be used in mutually exclusive manner  Critical region: code region accessing share variable

Mutual Exclusion Shared data! Critical region For shared data count

Condition Variables  wait for condition and wake up one thread  wait for condition and wake up all thread Shared variable Critical section mutex condition wait signal lock unlock

Example: Condition Variables