consider letting inetd launch your application. inetd daemon problems starting with /etc/rc(without...

20
Consider Consider Letting Letting inetd inetd Launch Your Application Launch Your Application

Upload: jocelyn-patterson

Post on 13-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

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

ConsiderConsider Letting Letting inetdinetd Launch Launch Your ApplicationYour Application

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

inetdinetd daemon 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

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

Steps performed by Steps performed by inetdinetd

dup2(sockfd, 0);dup2(sockfd, 1);dup2(sockfd, 2);close(sockfd);

Open descriptor 들은 fork 시 copy 되고Exec 후에도 유지된다 .Exec 후에 Peer 를 알 수 있는 방법은 ?

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

Consider Consider Using Two TCP ConnectionsUsing Two TCP Connections

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

Concurrent Input/Output processesConcurrent 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

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

ExampleExample

xout1.c:

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

Interprocess CommunicationInterprocess Communicationvia UNIX Domain Protocolsvia UNIX Domain Protocols

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

UNIX Domain SocketsUNIX 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 (receivermay 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

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

UNIX Domain Stream Client/ServerUNIX Domain Stream Client/Serverunixdomain/unixstrcli01.c unixdomain/unixstrserv01.c

UNP

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

UNIX Domain Datagram ProtocolUNIX Domain Datagram Protocolunixdomai/unixdgcli01.c unixdomai/unixdgserv01.c

Binding client address (pathname) is necessary to identify client

UNP

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

ThreadsThreads

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

IntroductionIntroduction

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

10 - 100 times faster than process creation

Many different thread implementation Pthread: Posix thread

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

Shared and Own data in ThreadsShared 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

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

Thread Creation and TerminationThread 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

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

A Simpler Version of A Simpler Version of str_clistr_cli using Threadsusing Threads

UNP

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

TCP Echo Server using ThreadsTCP Echo Server using Threadsthreads/tcpserv01.c threads/tcpserv02.c – more portable

UNP

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

Non-determinism causes time-dependent errorsNon-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 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

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

Mutual ExclusionMutual Exclusion

Shared data!

Critical regionFor shared datacount

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

Condition VariablesCondition 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

lockunlock

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

Example: Condition VariablesExample: Condition Variables