OS/IPC 3

[OS] Signaling

Signaling 예제 코드 #include #include #include #include #include // 핸들러 함수 정의 void handlerFunc(int sig) { printf("handlerFunc() 호출됨\n"); // SIGINT : 터미널 인터럽트 // SIG_DFL : 기본 행동 수행, 메인 함수가 하던 일을 계속 수행하고 한 번 더 SIGINT가 오는 경우 프로세스 종료 signal(SIGINT, SIG_DFL); } int main() { // SIGINT(키보드 인터럽트) 신호를 받으면 handlerFunc 수행 signal(SIGINT, handlerFunc); int count = 0; while(1) { printf("count : %d\n", count++); s..

OS/IPC 2022.12.26

[OS] IPC - Message Passing

프로세스, 스레드, IPC에 관한 내용은 이 글을 참고하자 Message Passing 예제 sender.c #include #include #include #include #include #include #include #define BUFFER_SIZE 1024 // 메세지 형태 정의 typedef struct { long msgtype; int value; char buf[BUFFER_SIZE]; } msgbuf; int main() { int key_id; msgbuf mybuf; int count = 0; // 메세지 생성 key_id = msgget((key_t) 1234, IPC_CREAT|0666); if (key_id == -1) { perror("msgget() error"); exit..

OS/IPC 2022.12.26

[OS] IPC - Shared Memory

Process 컴퓨터에서 실행되고 있는 프로그램 실행되고 있는 프로그램의 인스턴스 프로세스간 독립적 CPU로부터 메모리 할당 Thread 프로세스 내에서 실행되는 흐름의 단위 프로세스가 할당받은 자원을 이용 같은 메모리 공간 공유 IPC 프로세스는 독립적으로 실행되기 때문에 메모리를 공유할 수 없다. 따라서 프로세스간 통신을 통해 서로 데이터를 주고 받을 수 있게 해야한다. 방법은 다음과 같다. 1) Message Passing 커널을 통해 메시지를 전달 안전하지만 성능이 떨어짐 (Overhead가 큼) 예제 2) Shared Memory 프로세스간 공유된 메모리를 생성 후 이용 성능이 좋지만 동기화 문제 발생 가능 #include #include #include #include #include int ..

OS/IPC 2022.12.26