동시에 프로그램을 실행하는 방법(process, thread)
프로그램
컴퓨터가 실행할 수 있는 명령어의 집합
프로세스(process)
- 컴퓨터에서 실행 중인 프로그램
- 각각의 프로세스는 독립된 메모리 공간을 할당 받음
- code, data, stack, heap
- 독립된 메모리 공간을 가지기 때문에 다른 프로세스의 자원에 접근하기 위해선 IPC(inter-process communication)를 사용해야 한다.
멀티 프로그래밍
- 단일 프로세스 시스템에서는 프로세스가 I/O 작업 등을 만나 대기하게 되면 CPU가 놀게 된다.’
- 이를 해결하기 위해 한 CPU에 여러 프로세스를 동작 시키는 멀티 프로그래밍이 등장
- 멀티 프로그래밍은 CPU 사용률을 극대화 시키는데 목적
- 단점
- CPU 사용 시간이 길어지면 다른 프로세스는 계속 대기해야 한다.
멀티 태스킹
- 프로세스가 한 번 CPU를 사용할 때 아주 짧은 시간(quantum)만 CPU에서 실행되도록 하는 방식
- 프로세스들이 번갈아가며 CPU를 점유하니 한 프로세스가 계속 기다려야 할 일이 사라진다.
- 프로세스의 응답 시간을 최소화 시키는데 목적
- 단점
- 하지만 여전히 하나의 프로세스가 동시에 여러 작업을 수행하지는 못한다.
- 여러 프로세스를 수행하면 되지만 프로세스의 컨텍스트 스위칭은 무거운 작업이다.
- 프로세스끼리 데이터 공유가 까다로움
스레드(Thread)
- 스레드는 프로세스의 작업 흐름을 말한다.
- 프로세스는 한 개 이상의 스레드를 가질 수 있다.
- 한 프로세스 내에서 스레드들은 stack만 따로 할당 받고, code, data, heap 영역은 공유한다.
멀티 스레딩
- 하나의 프로세스가 동시에 여러 작업을 실행하는데 목적
- 장점
- Responsiveness - 프로세스 내부의 일부 스레드가 차단되더라도 다른 스레드들은 계속 실행될 수 있다.
- Resource Sharing - 스레드는 프로세스의 리소스를 공유할 수 있다.
- Economy - 스레드의 생성과 컨텍스트 스위칭은 프로세스의 생성과 컨텍스트 스위칭보다 저렴하다.
- Scalability - 멀티 코어 아키텍처를 활용할 수 있다.
- 단점
- 메모리 영역을 공유하기 때문에 주의 깊은 설계가 필요하다. (자원 공유)
멀티 프로세싱
- 두 개 이상의 프로세서나 코어를 활용하는 시스템을 멀티 프로세싱이라고 한다.
- 멀티 스레딩이나 멀티 태스킹 환경이라 하더라도 코어가 하나라면 멀티 프로세싱이라고 볼 수 없다.
https://www.youtube.com/watch?v=QmtYKZC0lMU
Operating System Concepts - Tenth Edition
https://gmlwjd9405.github.io/2018/09/14/process-vs-thread.html