> Control flow (제어 흐름)
# 프로세서는 한 번에 하나의 instruction을 실행한다.
시작부터 끝까지, CPU는 일련의 instuction들을 하나씩 읽고 처리한다.
-> CPU's control flow; 프로그램에서 실행되는 각 구문, 명령어나 함수가 호출되는 순서
> Altering the Control Flow
순차적으로 진행되는 제어 흐름의 변화를 일으키는 요인
# program state를 변화시키는 요소
- Jumps and branches
- Call and return
# system state를 변화시키는 요소 -> exceptional control flow 발생
- Data arrives from a disk or a network adapter
- Instruction divides by zero
- Ctrl+C를 통한 프로시져 종료
- system timer expires
> Exceptional Control Flow (ECF)
모든 단계의 computer system에 존재한다.
# Low level mechanism - Exceptions
Exception; 이벤트에 대해 OS kernel에 제어를 전송
** kernel; 컴퓨터의 운영 체제(OS)의 핵심이 되는 컴퓨터 프로그램으로, 시스템의 모든 것을 통제하고, 응용 프로그램 수행에 필요한 서비스를 제공한다.
# High level mechanism - Process context switch/ Signals/ Nonlocal jumps
> Asynchronous Exceptions (비동기식 인터럽트) => Interrupt
# 정해진 기준없이 예측 불가능하게 이벤트 발생
# 다른 하드웨어 장비가 CPU와 상관없이 발생시킴
# Example: Timer interrupt/ I/O interrupt form external device
> Synchronous Exceptions (동기식 인터럽트) => Exception
# 이벤트가 예측 불가능하게 발생하는 것이 아니라 기준에 맞추어 또는 시간에 맞추어 수행시키는 것을 의미
# 내부적으로 CPU control unit이 명령어의 실행결과로 자주 발생시킴
(Intel CPU에서 사용되는 exception의 분류)
# trap: INT 명령으로 명시적 발생
- Intentional
- Examples: system calls, breakpoint traps, special instructions
- Returns control to “next” instruction
# fault: 0으로 나눈 에러
- Unintentional but possibly recoverable
- Examples: page faults (recoverable), protection faults (unrecoverable), floating point exceptions
- Either re-executes faulting (“current”) instruction or aborts
# abort: 복구 불가능한 에러
- Unintentional and unrecoverable
- Examples: illegal instruction, parity error, machine check
- Aborts current program
> Processes
# Process; 프로그램(program)의 인스턴스(instance)
# 2개의 key abstractions
- logical control flow; 각 프로그램에 프로세서를 혼자 사용한다는 착각을 제공 -> context switching
- private address space; 각 프로그램에 메모리를 혼자 사용한다는 착각(각 프로그램에 할당된 사적 주소공간의 메모리는 다른 프로세서가 읽거나 쓸 수 없다) -> virtual memory
> Multiprocessing
# The Traditional Reality
단일 프로세서가 여러 프로세스를 동시에 실행한다.
# The Modern Reality -> multicore processors
> Concurrent Processees ( 동시성 흐름 )
동시성 흐름이란, 동시에 실행된다는 개념보다는 다른 논리 흐름과 실행시간이 겹치는 흐름을 의미한다.
> Context Switching ( 문맥 전환 )
커널은 문맥 전환(context switch)을 통해 멀티태스킹을 구현
** 문맥(context)은 커널이 선점된 프로세스를 다시 시작하기 위해 필요로 하는 일종의 상태
> System Call Error Handling
# return -1
# set global variable errno to indicate cause
> Creating Processes
fork를 통해 부모 프로세스는 자식 프로세스를 생성
# int fork(void)
자식 프로세스에게는 0을 반환하고, 부모 프로세스에게는 자식의 PID를 반환한다.
- call once, return twice
- concurrent execution (동시에 실행); 실행 순서를 예측할 수 없다.
- 주소 공간을 복제 BUT 개별적으로 분리
- Shared open files
'소프트웨어 전공 > 시스템 프로그램' 카테고리의 다른 글
[System Program] [7] [Virtual Memory] (0) | 2021.05.31 |
---|---|
[System Program] [9] Concurrent Programming (0) | 2021.05.31 |
[System Program] [4] Cache Memory (0) | 2021.05.30 |
[System Program] [3] Memory Hierarchy (0) | 2021.05.29 |
[System Program] [1] Data Presentation (0) | 2021.05.25 |