05.프로세스간 통신(IPC)

개발 99·2025년 4월 3일

공룡책

목록 보기
5/22

Processes는

  • independently
    : 메모리 영역이 서로 분리되어서 작동한다.(공유하는 데이터가 없다)

  • cooperating
    : 서로 간섭을 받는다.(공유하는 데이터가 존재한다.)

IPC(Inter-Process Communication)

Cooperating system은 IPC 메커니즘이 필요한데, data를 주고받는다.

2가지 방법

  • shared memory
    : shared memory의 공통의 메모리에서 데이터를 공유한다.

  • message passing(메시지 교환)
    : kernel에 맡긴다.

Producer-Consumer Problem

1. Shared Memory( 동기화 문제, race condition )

Ex)
complier가 assembly code를 생성하면, assembler가 그것을 소비한다.

web server가 HTML 파일을 만들면, browser가 그것을 소비한다.

여기서 buffer를 shared memory(buffer)로 만들어서

  • producer는 buffer를 계속 채우고, 가득차면 wait()

  • consumer는 buffer를 계속 소비를 하는데, size가 0이면 wait()

참고로, process간 private를 유지해야만 한다.(서로 독립적)

그러나, 공유 메모리를 직접 관리를 해야한다. 같은 메모리 영역을 여러 프로세스가 공유하기에 적절한 동기화가 필요하다.

2. Message-Passing

OS가 cooperating process들에게 message passing API를 제공.

  • send(message)

  • receive(message)

P와 Q Process가 있다면, 서로 링크를 통해서 message를 주고받는다.

  1. direct? indirect?
  • direct
    "수신자를 명시"해서 message를 전송한다.
    send( P,message ) : send a message to P
    receive( Q,message ) : receive a message from process Q
    1:1 Link만 가능함.

  • indirect
    중간에 mailbox(port)가 있음.
    mailbox에는 message가 IN/OUT이 가능함.
    send( A,message ) : send a message to mailbox A
    receive( A,message ) : receive a message from mailbox A
    Producer : Mailbox : Consumer = N : 1 : N
    ( 메시지 큐? )
    port번호도 mailbox임.

1-2. synchronous(block)? asynchronous(non-block)?

  • Blocking send : send를 완료할 때까지, 다른 작업을 수행할 수 없다.

  • Non-blocking send : sender는 message를 보내면서 다른 task를 수행할 수 있다.

  • Blocking receive

  • Non-blocking receive

synchronous Vs. asynchronous

asynchronous는 요청/응답의 순서가 보장되지 않는다.
대신 synchronous보단 속도는 빠른다.

1-3. automatic? explicit buffering?

profile
구구구구구!

0개의 댓글