아주대학교 김상훈 교수님의 운영체제 강의와 강의 자료를 바탕으로 작성된 글입니다.
Inter-Process Communication
- Processes within a system may be independent or cooperating
- Independent processes cannot affect or be affected by the execution of another process
- Cooperating process can affect or be affected by other processes, including the procedure of sharing data
Singals
- An IPC mechanism to notify a process of a particular event
- Can be synchronous(e.g. illegal memeory access) or asynchronous(e.g., killed)
- Can be thought as a software interrupt
- signal is generated by particular/some events
- OS delivers the signal to the process
- Signal handlers process the signal
- Every signal has its corresponding default signal handler
- User can overrride some handlers
=> 특정 event가 발생다는 사실을 다른 process에게 알리기 위한 software interrupt
Signal Handling
- Action
- Term: terminate (대부분 시그널 받으면 죽게끔 되어 있다.)
- Core: 현재 메모리를 어디 파일 같은 곳에 쓰고 죽어라
- Ign: 무시, 아무것도 안 하겠다

- A process can define a signal handler for a signal
- sigaction(SIGALRM, &sa, $old_sa) => 운영체제야, SIGALRM이 오면 내가 custom한 sa를 불러줘

Pipes
- A conduit allowing two processes to communicate
- Issues
- Is communication undirectional or bidirectional?
- uni: 데이터가 한 방향으로만 흐를 수 있음
- bi: 데이터가 양방향으로 흐를 수 있음
- Is the case of bidirectional one, is it half or full-duplex?
- half: 한 시점에 보내고 받는 것 중 하나만 할 수 있음 또한 한 프로세스가 쓰고 있을 때 다른 프로세스는 쓸 수 없음
- full: 한 시점에 보내고 보내고 받는 걸 동시에 할 수 있음
Ordinary pipes
- only one-way
- Require parent-child relationship between communicating processes
- fd[0]으로 읽고 fd[1]로 씀

- ordinary pipes are unidirectional
- 단방향으로 데이터를 전송하므로, 부모가 데이터를 쓰면 자식이 그 데이터를 읽는 구조이거나, 자식이 데이터를 쓰면 부모가 읽는 구조
- File descriptor
- An abstract indicator used for processing a file or other input/output resource
(운영체제가 관리하는 굉장히 많은 system resource들은 user에게 file descriptor라는 concept으로 abstract하게 제공된다.)
- fork를 할 때는 기존에 있던 file descriptor 값들도 그대로 복사되어 넘어가고, 그 file descriptor와 associate된 resource들도 똑같이 공유된다.
- 부모가 fd = open("my_file", "r") 실행
- 자식이 write(fd, "hi it's me", strlen("hi it's me"))
- 부모도 hi it's me를 읽을 수 있음
- 즉, 하나의 파일을 대상으로 여러 operation이 작용
- fork 를 할 때 signal handler도 그대로 넘어간다.
- 수정된 signal handler도 같이 넘어감