[OS] IPC in UNIX, Pipe, Socket

Ko Hyejung·2021년 10월 11일
0

Operating Systems

목록 보기
11/26

IPC in UNIX

Inter-Process Communication : Mechanism for various processes to communicate among them.
다양한 프로세스가 프로세스 간에 통신하기 위한 메커니즘

  • Different processes run on different address space.
    각기 다른 프로세스가 각기 다른 주소 공간에서 실행
  • OS needs to provide mechanisms to communicate -> IPC.
    OS는 통신하기 위한 메커니즘을 제공 -> IPC.

Types of IPCs in UNIX

  • Traditional UNIX IPCs : signal, pipe, socket
  • System V IPCs : message queue, semaphore, shared memory

Pipe


Unidirectional byte streams which connect one process into the other process.
한 프로세스를 다른 프로세스에 연결하는 단방향 바이트 스트림

  • The data written at one end of the channel is read at the other end.
    채널의 한 쪽 끝에서 기록된 데이터를 다른 쪽 끝에서 읽습니다.
  • From a logical point of view, a pipe can be compared to a FIFO queue of characters.
    논리적인 관점에서 파이프는 문자의 FIFO 큐와 비교될 수도
  • No structured communication
    It is not possible to know the size, sender/receiver of data contained in the pipe.
    구조화된 통신 없음 : 파이프에 포함된 데이터의 크기, 송신자/수신자를 알 수 없음

  • Access to pipes is achieved by reading / writing from/to file descriptors.

Pipe Used by Commands


One current usage of the pipe mechanism is performed by means of the command line interpreter when commands are linked:

파이프 메커니즘의 현재 사용 중 하나는 명령이 연결된 경우 명령줄 인터프리터를 통해 수행됩니다.

(e.g., > ps -aux | grep root | tail)

Ordinary (Anonymous) Pipe


Created by a process and the transmission for associated descriptors is achieved only by inheritance by its descendants (parent <-> child).

프로세스에 의해 생성되고 관련 설명자에 대한 전송은 하위 항목에 의한 상속에 의해서만 수행됨

(i.e., by creating a child process using fork() system call)

Restrictive in that it only allows communication between processes with a common ancestor which is a creator of a pipe.

파이프의 작성자인 공통 조상을 가진 프로세스 간의 통신만 허용한다는 점에서 제한적

Use of Pipe Example

fd[0] : read
fd[1] : write
"Hello World"

Named Pipe (FIFO)

Remove the constraint of anonymous pipe (i.e., no name, only used between processes that have a parent process in common) because they are entries in the file system.

익명 파이프는 파일 시스템의 항목이기 때문에 해당 제약 조건을 제거

Has a name and handled exactly like files with respect to file operations (e.g., open, close, read, write).

Created by mkfifo or mknod commands.

Can be created by C functions : mkfifo().

  • int mkfifo(const char *path, mode_t mode);

Reading from / writing to a named pipe can be achieved by using standard read() and write() system calls.

Communication in Client-Server Systems

  • Sockets
  • Remote Procedure Calls

Sockets


A socket is defined as an endpoint for communication.

소켓은 통신을 위한 끝점으로 정의

Concatenation of IP address and port number

IP 주소포트 번호의 연결

The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
Communication consists between a pair of sockets.

Socket Communication

Remote Procedure Calls


Remote procedure call (RPC) abstracts procedure calls between processes on networked systems.

Main Components of RPC

0개의 댓글