IPC란
IPC는 프로세스들 간에 데이터를 교환하고 통신해 의사소통하는 기술을 나타냅니다.
이는 컴퓨터 프로그래밍에서 다양한 프로세스나 스레드 간의 상호 작용을 가능케 하는 기술적인 용어입니다.
프로세스는 독립적으로 실행되는 프로그램 단위를 말하며 각각의 프로세스는 자체적인 메모리 공간을 가지고 (주소 공간이 분리)있기 때문에 한 프로세스는 직접 다른 프로세스의 메모리에 접근할 수 없습니다. 성능향상을 위해 멀티 프로세스 환경을 구성할 수 있는데 이때 프로세스간 상태 확인 및 데이터 송수신이 필요합니다.
따라서 프로세스들이 공유된 데이터에 접근하려면 특별한 수단이 필요하며, IPC 함수는 이를 가능케 합니다.
IPC를 이용하여 프로세스들이 효과적으로 통신하고 협력할 수 있게 하는 기술적인 접근을 제공합니다.
IPC 목적
데이터 교환
다른 프로세스 간에 데이터를 전송하고 공유할 수 있도록 합니다. 이를 통해 프로세스들은 정보를 주고받아 작업을 수행하거나 상태를 공유할 수 있습니다.
프로세스 동기화
여러 프로세스 간에 실행 순서를 조정하고 동기화하여 데이터 일관성을 유지하고 경합 상태를 방지합니다.
IPC 기법
이러한 IPC 함수는 다양한 형태를 가질 수 있습니다. 메시지 큐, 파이프, 공유 메모리, 소켓 등이 그 예시로 들 수 있습니다.
파일 사용
1. 메시지 큐(Message Queue)
프로세스 간에 메시지를 전송하는 큐를 사용하여 통신합니다.
2. 파이프(Pipe)
두 프로세스 간에 단방향 또는 양방향으로 데이터를 전송하는 파이프를 사용합니다.
3. 공유 메모리(Shared Memory)
여러 프로세스가 동일한 메모리 영역을 공유하여 데이터를 주고 받습니다.
4. 소켓(Socket)
네트워크 프로그래밍에서 사용되는 소켓을 통해 프로세스 간 통신 을 구현할 수 있습니다.
5. Semaphore
프로세스간 메시지 전송을 목적으로 하는 다른 IPC에 비해 세마포어는 프로세스 간 데이터를 동기화 하고 보호하는데 목적을 둡니다.
6. Signal
프로세스 ID를 통해 특정 프로세스에게 메시지를 전달하는 방식
이러한 함수들을 사용하여 프로세스 간에 데이터를 안전하게 전달하고 통신할 수 있습니다. 이것은 각 프로세스가 서로 독립적으로 실행되면서도 필요한 정보를 공유하고 협력하는 데에 중요한 역할을 합니다.
메시지 큐, 파이프, 공유 메모리는 프로세스가 공유할 수 있는 커널 공간에 메모리 공간을 만들고 해당 공간을 변수처럼 사용해 사용한다고 합니다.
vs 스레드
스레드는 하나의 프로세스 내에서 메모리 공간과 자원을 공유하기 때문에 따로 통신 기술이 필요 없습니다.
참고하기:
'knowledge > computer science' 카테고리의 다른 글
[네트워크] 쿠키와 세션 (1) | 2024.02.13 |
---|---|
[네트워크] TCP와 UDP (1) | 2024.02.06 |
[DB] 여러 트랜잭션이 경쟁하면 생기는 문제 (0) | 2024.02.01 |
[OS][Java] 인터럽트(Interrupt) interrupt() 함수 사용하기 (0) | 2024.01.29 |
[OS][Java] 쓰레드(Thread) (1) | 2024.01.23 |