null
vuild_
Nodes
Flows
Hubs
Login
MENU
Notifications
Login
⌂
c-lang-advanced
Structure
advanced-pointers
•
Function Pointer
•
Pointer to Pointer
•
Void Pointer
data-structures
•
Linked List
•
Stack & Queue
•
Tree & Graph
algorithms
•
Sorting Algorithms
•
Complexity Analysis
bit-ops
•
Bitwise Operators
•
Bit Fields
•
Bit Tricks
system-prog
•
Process
•
Signal
•
IPC (Inter-Process Communication)
concurrency
•
Threads Basics
•
Mutex & Semaphore
•
Race Condition
optimization
•
Compiler Flags
•
Cache Locality
•
Profiling
design-patterns
•
OOP in C
•
Callback Pattern
•
State Machine
project
•
Mini Shell
•
TCP Echo Server
Flow Structure
Signal
14 / 25
Threads Basics
☆ Star
↗ Full
IPC (Inter-Process Communication)
#c
#c-lang
#advanced
#system-programming
#ipc
@devpc
|
2026-03-29 13:49:34
|
GET /api/v1/flows/6/nodes/78?fv=1&nv=1
Context:
Flow v1
→
Node v1
0
Views
1
Calls
# IPC (Inter-Process Communication) > 파이프·공유 메모리·메시지 큐 개념과 사용법 ## 학습 목표 - 프로세스 간 통신(IPC)의 필요성을 이해한다 - 파이프, 공유 메모리, 메시지 큐를 사용할 수 있다 ## 내용 ### 익명 파이프 (pipe) ```c #include <unistd.h> int fd[2]; pipe(fd); // fd[0]: 읽기, fd[1]: 쓰기 if (fork() == 0) { close(fd[0]); write(fd[1], "hello", 5); close(fd[1]); } else { char buf[6] = {0}; close(fd[1]); read(fd[0], buf, 5); printf("Parent received: %s\n", buf); close(fd[0]); } ``` ### 공유 메모리 (POSIX) ```c #include <sys/mman.h> int *shared = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); *shared = 42; // fork() 후 자식도 같은 메모리 접근 가능 munmap(shared, sizeof(int)); ``` ### 메시지 큐 (POSIX) ```c #include <mqueue.h> mqd_t mq = mq_open("/myqueue", O_CREAT | O_RDWR, 0644, NULL); mq_send(mq, "hello", 5, 0); char buf[64]; mq_receive(mq, buf, sizeof(buf), NULL); mq_close(mq); mq_unlink("/myqueue"); ``` ## IPC 방식 비교 | 방식 | 속도 | 관계 | 특징 | |------|------|------|------| | 파이프 | 보통 | 부모-자식 | 단방향, 바이트 스트림 | | 공유 메모리 | 빠름 | 무관 | 동기화 필요 | | 메시지 큐 | 보통 | 무관 | 구조화된 메시지 | ## 참고 - 공유 메모리는 가장 빠르지만 mutex/semaphore로 동기화해야 한다
Signal
Threads Basics
// COMMENTS
ON THIS PAGE
No content selected.