- Process는 컴퓨터에서 실행되고 있는 하나의 프로그램이고, Thread는 프로그램 내 작업을 일컫는다
- Process는 프로그램이 메모리에 올라갈 때, 프로그램이 Process로 인스턴스화된 것을 말하며 컴파일 과정을 통해 Process를 실행한다
- 컴파일 과정 : 소스 코드 확인 → 컴파일러로 어셈블리어로 변환 → 어셈블러에서 변환한 코드 실행
PCB
- Process Control Block, OS에서 Process의 메타데이터를 저장한 데이터
- Process가 생성되면 메모리에 할당이 되고 해당 Process의 정보들이 이 PCB에 저장하는데, 아래와 같이 저장한다
- 스케줄링 상태 - 준비, 일시중단 같은 상태
- ID - 해당 Process의 ID 고유값
- 권한 - 컴퓨터 또는 I/O 디바이스에 대한 권한 정보
- CPU 레지스터 - Process를 실행하기 위해 저장해야 할 레지스터 정보
- CPU 스케줄링 정보 - CPU 스케줄러에 의해 실행된 시간 정보
- 기타 등등
- Context Switching은 이 PCB가 교환되는 과정을 말하는데, 하나의 Process의 할당된 시간이 끝날때 발생한다
- 여러 Process가 실행되고 있는 환경에서 기존 실행된 Process A의 상태값을 Ready 또는 Block으로 변경하고
- 다음 실행할 Process B를 Running 상태로 변경하여 실행하여 Process를 교체할 수 있다
- Thread 단위에서도 컨텍스트 스위칭이 발생하는데, Thread들은 메모리를 공유하기 때문에 스위칭이 더 빨리 수행된다고 한다
Multi Threading
- 한 Process 내 여러 Thread를 가지는 기법이며, Thread끼리는 메모리를 공유하기 때문에, 특정 Thread가 중단되어도 다른 Thread가 작업을 실행하여 빠른 작업 처리를 할 수 있다
- 다만 한 Thread가 문제가 생기면 다른 Thread에도 영향이 생겨 Process까지 영향을 미칠 수 있다
- Multi Processing인 경우는 서로 영향을 미치지 않는데, 각 Process가 서로 다른 주소의 메모리를 할당 받기 때문