#프로세스란?
컴퓨터 운영체제에서 프로세스란 컴퓨터에서 실행되고 있는 컴퓨터 프로그램을 말한다. 프로그램과 프로세스의 차이는 컴퓨터에 다운로드만 돼있는 명령어와 정적 데이터는 프로그램이고, 그 프로그램을 실행시키는 순간 프로세스가 된다. 운영체제는 각 프로세스 마다 locial flow를 부여하고 single-thread 프로그램은 하나, multi-thread 프로그램에는 여러 개의 flow를 부여한다. 또, 운영체제는 private, protected address space와 같은 memory address를 부여하고 file descriptor와 같은 abstracted resources도 부여한다.
# Context Switching
Context switching은 CPU가 현재 실행하고 있는 process를 저장하는 역할을 하고 다음 process의 register값 (context)을 읽어 다음 process의 context로 switch하는 과정이다. 여기서 context란, 프로그램 텍스트, 프로그램 텍스트의 위치(PC/IP), 그 외의 변수들(글로벌, 힙, 스택, cpu register 등등) 현재 실행되고 있는 프로그램의 상태 정보를 말한다. 보통 context swiching은 kernel이 관리기 때문에 mode-switching과도 상호작용한다.
Time sharing: 모든 프로세스가 진행되도록 하기 위해 정기적으로 다른 프로세스로 전환하는 정책
# Dual Mode Operation (이중 동작 모드)
Dual Mode Operation 이란, 최근 OS에서 여러 프로그램을 동시 실행이 가능해지게 되면서, 하나의 프로그램이 실행되어 서 다른 프로그램에 영향을 미치게 되니 나타나게 된 hardware protection 이다. 이 Dual Mode Operation에서는 크게 2가지 모드가 있다. 그 2가지 모드는 Kernel mode 와 user mode가 있다. Kernel mode는 흔히 system mode, supervisor 혹은 monitor mode로 불린다. Intel 에서는 PL0 (Privilege Level 0) 로 불린다. User mode는 반대로 non-privilege mode로 불리며, intel에서는 PL3(Privilege Levle 3)로 불린다. 이 모드들은 CPU에 의해 유지되며, "privileged" instruction들은 kernel mode에서 밖이 실행이 되지 않는다, 만약 kernel에서 실행되지 않으면 trap를 발생시킨다.
# Mode Switching
Mode switching 이중 동작 모드 사이에서 kernal mode와 user mode를 바꾸는 것이다. 예를 들어
user mode -> kernel mode, 반대로 kernel mode -> user mode와 같은 것이 mode switching이다. 이 mode switching은 아래 3가지 경우에 일어 날 수 있다.
- User->Kernel mode
- External interrupt (외부 인터럽트 또는 하드웨어 인터럽트): 타이머, clock chip, I/O 디바이스, 네트워크 카드, 키보드, 마우스 등등.
- Internal interrupt (내부 인터럽트 또는 소프트웨어, trap (aka system call), exception 인터럽트): invalid operation (0으로 나누기), user mode에서 privileged instruction 실행 시도, memory access violation, invalid instruction, alignment error, page fault 등등.
- System Call (시스템 콜): I/O instruction, fork, trap(프로세스가 service를 얻기 위해 kernel에 enter해야 되는 상황).
- Kernel mode->User mode
- privileged instruction 을 통해 가능 (Intel: iret)
- represents either a return from interrupt or careful action to resume user program execution
# Context vs Mode Switches Summary
- Mode switch guarantees that kernel gains control when needed
- To react to external events
- To handle error situations
- Entry into the kernel is controlled
- Not all mode switches lead to context switches
- kernel decides if/when - subject to process state transitions and scheduling policies
- Mode switch does not change the identity of the current process/thread
# Exceptions, Bottom-Up View
'Computer Science > Computer Systems' 카테고리의 다른 글
[Lecture 3] Unix Signals (0) | 2022.09.15 |
---|---|
[Lecture 2] Unix File Descriptors and Pipes (0) | 2022.09.10 |
[Lecture 1-3] Processes Part III (0) | 2022.09.04 |
[Mini-Lecture] Character Sets and Unicode (0) | 2022.09.04 |
[Lecture 1-2] Processes Part II (Process State) (0) | 2022.08.30 |