Linux system의 Multitask
여러 개의 Process를 Memory에 올려놓고 Time slicing과 Scheduling해서 1 time에 하나 씩 실행시킨다.
- 특정 시간동안 한 process를 실행하고 다른 process를 idle상태로 만든다.
- 특정 시간 마다 타이머 주기를 맞추고 Context switching 한다.
- swithching할때 CPU는 CPU에 점유하는 Process Control Block을 바꿔주는 작업을 한다.
- 실행중인 Process를 scheduler의 stack 영역에 저장한다. & idle상태 process의 control block 복구해서 CPU의 register에 적재하고 실행한다.
- 이런 작업을 반복한다.
Problem
여러 개의 process를 한 cpu에서 실행시키면 문제가 발생할 수 있다.
미리 인지하지 않으면 복구할 수 없을 수 잇다.
2개의 proces가 경쟁을 하는 상태(race condition)
z.B) fork로 두개의 프로세서에서 file copy하면 읽고 쓰는게 섞일 수 있다.
Inter-Process Communication(IPC)
problem을 제거하는 interface
Communications 하는 가능한 방법
- file을 공유 // 두 process간에 통로가 되는 file을 사용한다.
- 부모와 자식이 open한 file poiter를 공유한다.
- message queue
- semaphores (explained later)
- signals (ref. SP)
- network sockets
- pipe : circular queue bet. processes // process간의 circular queue를 만들어 data를 주고받는 방식
– named pipe : between any processes in a system
– unnamed pipe : between parent and children
Pipe
- 2개의 process 사이의 interface communication하는 방식
- block & wakeup으로 race conditon을 피할 수 있다.
- 한쪽은 read만 할 수 있고 한쪽은 write만 할 수있는 pipe를 생성한다.
- System 입장에서 pipe를 Ring구조의 Circular형태로 만든어서 data를 덮어쓴다.
- Read입장에서 write한 data가 없으면 기다리고 write하면 read한다.
'시스템 프로그래밍' 카테고리의 다른 글
시스템 프로그래밍 5장 - Process Control : Process Start & Exit (0) | 2020.05.05 |
---|---|
시스템 프로그래밍 5장 - Process Control : PID (0) | 2020.05.05 |
시스템 프로그래밍 4장 - Concurrent Process (0) | 2020.05.05 |
시스템 프로그래밍 3장 - System call : File I/O Permission, ID (0) | 2020.05.05 |
시스템 프로그래밍 3장 - System call : File I/O (0) | 2020.05.05 |