[OS] Process, Interrupt & Exception

seunghyunยท2023๋…„ 3์›” 24์ผ
0

๐Ÿ’ป

๋ชฉ๋ก ๋ณด๊ธฐ
1/16

Introduction

ISA (Instruction Set Architecture)

โœ”๏ธ ๋ชจ๋“  ์ปดํ“จํ„ฐ๋Š” ์ž๊ธฐ ์ž์‹ ๋งŒ์˜ ์–ธ์–ด๋ฅผ ๊ฐ€์ง„๋‹ค.
โœ”๏ธ machine ์˜ state ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” ๋ช…๋ น์–ด์˜ ์ง‘ํ•ฉ ๊ทธ๋ฆฌ๊ณ  ๊ทธ์— ํ•„์š”ํ•œ ๊ตฌ์กฐ๋“ค์ด๋‹ค.
โœ”๏ธ ๊ณ ์ˆ˜์ค€ ์–ธ์–ด์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์†Œํ”„ํŠธ์›จ์–ด๊ฐ€ ์‹œ์Šคํ…œ ์†Œํ”„ํŠธ์›จ์–ด์ธ ์–ด์…ˆ๋ธ”๋Ÿฌ์™€ ์ปดํŒŒ์ผ๋Ÿฌ๋ฅผ ๊ฑฐ์ณ ๋กœ์šฐ ๋ ˆ๋ฒจ์˜ ์–ธ์–ด๋กœ ๋ฒˆ์—ญ๋˜์–ด ํ•˜๋“œ์›จ์–ด์™€ ๋งˆ์ฃผํ•˜๊ฒŒ ๋˜๋Š” ์˜์—ญ, ์ด๋Ÿฌํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์นญํ•œ๋‹ค.

program

โœ”๏ธ ์ปดํ“จํ„ฐ ๋””์Šคํฌ์— ์ €์žฅ๋˜์–ด์žˆ๋Š” ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ์‹คํ–‰ํŒŒ์ผ๋กœ(.exe), a sequence of machine instruction ์ด๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค.

process

โœ”๏ธ A process is an instance of a program in execution : ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ์˜ ํ•œ ์ธ์Šคํ„ด์Šค
โœ”๏ธ ํ”„๋กœ์„ธ์Šค๋Š” ์ƒํƒœ๋ฅผ ๊ฐ€์ง„๋‹ค.
โœ”๏ธ Logical control flow : Each process has an exclusive use of the processor.
โœ”๏ธ Private address space : Each process has an exclusive use of private memory.

๊ฐ๊ฐ์˜ ๋…๋ฆฝ์ ์ธ ํ”„๋กœ์„ธ์Šค๋Š” CPU๋ฅผ ํ˜ผ์ž์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค. (virtual memory)
๋ฉ€ํ‹ฐํƒœ์Šคํ‚น์— ์˜ํ•ด์„œ ์ผ์ • ์‹œ๊ฐ„์„ ์ฃผ๊ณ  ๋Œ์•„๊ฐ€๋ฉด์„œ (time slice) ๊ฐ€๋Šฅํ•˜๋‹ค.

process control block

โœ”๏ธ A data structure in the OS Kernel that contains the information needed to manage a particular process
โœ”๏ธ ์ด ์ค‘ register state ๋ฅผ context ๋ผ ํ•œ๋‹ค.
โœ”๏ธ Created and managed by the operating system

kernel

โœ”๏ธ ์ปดํ“จํ„ฐ์˜ ํ•˜๋“œ์›จ์–ด ์ž์›๊ณผ ์ถ”์ƒํ™” ์ž์›์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ํฐ ๋ชฉํ‘œ์ด๋‹ค. ์ถ”์ƒํ™”๋ž€ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ํ•˜๋‚˜๋ฟ์ธ ํ•˜๋“œ์›จ์–ด๋ฅผ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž๋“ค์ด ๋ฒˆ๊ฐˆ์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งˆ์น˜ ์—ฌ๋Ÿฌ๊ฐœ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ ํ•˜๋Š” ๊ธฐ์ˆ ์ด๋‹ค. ์ž์›์œผ๋กœ๋Š” CPU task & process, ๋ฉ”๋ชจ๋ฆฌ page & segmetn, ๋””์Šคํฌ ํŒŒ์ผ, ๋„คํŠธ์›Œํฌ ์†Œ์ผ“ ๋“ฑ์ด ์žˆ๋‹ค.

context

โœ”๏ธ The kernel maintains a context for each process
โœ”๏ธ The context is the state of a process that the kernel needs to restart a preempted process

scheduling

โœ”๏ธ ์‹คํ–‰ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ๋Š” ํ”„๋กœ์„ธ์Šค๋Š” ready ์ƒํƒœ๋กœ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ๋˜์–ด ์žˆ๋‹ค. ๋‹ค์Œ์— ์–ด๋–ค ํ”„๋กœ์„ธ์Šค๋ฅผ CPU์— dispatch ํ• ๊นŒ?
โœ”๏ธ ready queue, ์šฐ์„ ์ˆœ์œ„๋ฅผ ๋”ฐ์ ธ์„œ dispatch ํ•œ๋‹ค.
โœ”๏ธ ๊ทธ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ณตํ‰ํ•˜๊ฒŒ ํ•˜๋„๋ก ํ•˜๋Š” ๊ณผ์ •
โœ”๏ธ kernel ์—์„œ scheduling ์„ ๋‹ด๋‹นํ•˜๋Š” ๊ฒƒ์„ dispatcher ๋ผ ํ•œ๋‹ค.

timer

โœ”๏ธ ์ •ํ•ด์ง„ ์‹œ๊ฐ„์ด ํ๋ฅธ ๋’ค ์šด์˜์ฒด์ œ์—๊ฒŒ ์ œ์–ด๊ถŒ์ด ๋„˜์–ด๊ฐ€๋„๋ก ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค
โœ”๏ธ ํƒ€์ด๋จธ๋Š” ๋งค ํด๋Ÿญ ํ‹ฑ ๋•Œ๋งˆ๋‹ค 1์”ฉ ๊ฐ์†Œ
โœ”๏ธ ํƒ€์ด๋จธ ๊ฐ’์ด 0์ด ๋˜๋ฉด ํƒ€์ด๋จธ ์ธํ„ฐ๋ŸฝํŠธ ๋ฐœ์ƒ
โœ”๏ธ CPU๋ฅผ ํŠน์ • ํ”„๋กœ๊ทธ๋žจ์ด ๋…์ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธ

  • ํƒ€์ด๋จธ๋Š” time sharing ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋„๋ฆฌ ์ด์šฉ๋จ
  • ํƒ€์ด๋จธ๋Š” ํ˜„์žฌ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋„ ์‚ฌ์šฉ

mode bit

โœ”๏ธ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์˜ ์ž˜๋ชป๋œ ์ˆ˜ํ–‰์œผ๋กœ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ ๋ฐ ์šด์˜์ฒด์ œ์— ํ”ผํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š๋„๋ก ํ•˜๊ธฐ ์œ„ํ•œ ๋ณดํ˜ธ ์žฅ์น˜ ํ•„์š”
โœ”๏ธ Mode bit ๋ฅผ ํ†ตํ•ด ํ•˜๋“œ์›จ์–ด์ ์œผ๋กœ ๋‘ ๊ฐ€์ง€ ๋ชจ๋“œ์˜ operation ์„ ์ง€์›ํ•œ๋‹ค

  • 1 ์‚ฌ์šฉ์ž๋ชจ๋“œ : ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ ์ˆ˜ํ–‰
  • 0 ๋ชจ๋‹ˆํ„ฐ๋ชจ๋“œ : OS ์ฝ”๋“œ ์ˆ˜ํ–‰
    • ๋ณด์•ˆ์„ ํ•ด์น  ์ˆ˜ ์žˆ๋Š” ์ค‘์š”ํ•œ ๋ช…๋ น์–ด๋Š” ๋ชจ๋‹ˆํ„ฐ ๋ชจ๋“œ(์ปค๋„๋ชจ๋“œ, ์‹œ์Šคํ…œ๋ชจ๋“œ) ์—์„œ๋งŒ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅํ•œ ํŠน๊ถŒ๋ช…๋ น์œผ๋กœ ๊ทœ์ •
    • Interrupt ๋‚˜ Exception ๋ฐœ์ƒ์‹œ ๐Ÿ‘‰ ํ•˜๋“œ์›จ์–ด๊ฐ€ mode bit ์„ 0 ์œผ๋กœ ์„ธํŒ…
    • ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์—๊ฒŒ CPU ๋ฅผ ๋„˜๊ธฐ๊ธฐ ์ „์— ๐Ÿ‘‰ mode bit ์„ 1 ๋กœ ์„ธํŒ…

DMA (Direct Memory Access)

โœ”๏ธ ๋น ๋ฅธ ์ž…์ถœ๋ ฅ ์žฅ์น˜๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ๊ฐ€๊นŒ์šด ์†๋„๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
โœ”๏ธ CPU์˜ ์ค‘์žฌ ์—†์ด device controller๊ฐ€ device์˜ buffer storage ์˜ ๋‚ด์šฉ์„ ๋ฉ”๋ชจ๋ฆฌ์— block ๋‹จ์œ„๋กœ ์ง์ ‘ ์ „์†ก
โœ”๏ธ ๋ฐ”์ดํŠธ ๋‹จ์œ„๊ฐ€ ์•„๋‹Œ block ๋‹จ์œ„๋กœ ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ๋ฐœ์ƒ


Process

Creation

โœ”๏ธ Parent Process ๊ฐ€ Children Process ๋ณต์ œ ์ƒ์„ฑ

โœ”๏ธ ํ”„๋กœ์„ธ์Šค์˜ ํŠธ๋ฆฌ (๊ณ„์ธต ๊ตฌ์กฐ) ํ˜•์„ฑ

โœ”๏ธ ํ”„๋กœ์„ธ์Šค๋Š” ์ž์›์„ ํ•„์š”๋กœ ํ•จ

  • ์šด์˜์ฒด์ œ๋กœ๋ถ€ํ„ฐ ๋ฐ›๋Š”๋‹ค ๐Ÿ‘‰ System Call fork()
  • ๋ถ€๋ชจ์™€ ๊ณต์œ ํ•œ๋‹ค (์ด๋ก€์ ์ž„, ๋ถ€ํ†ต ๊ฒฝ์Ÿํ•œ๋‹ค)
int main()
{
	int pid;
    pid = fork();
    if (pid == 0) 
    	printf ("I am child\n");
    else if (pid > 0) 
    	printf ("I am parent\n");
}

โœ”๏ธ ์ž์›์˜ ๊ณต์œ 

  • ๋ถ€๋ชจ์™€ ์ž์‹์ด ๋ชจ๋“  ์ž์›์„ ๊ณต์œ ํ•˜๋Š” ๋ชจ๋ธ
  • ์ผ๋ถ€๋ฅผ ๊ณต์œ ํ•˜๋Š” ๋ชจ๋ธ
  • ์ „ํ˜€ ๊ณต์œ ํ•˜์ง€ ์•Š๋Š” ๋ชจ๋ธ

โœ”๏ธ ์ˆ˜ํ–‰ (Execution)

  • ๋ถ€๋ชจ์™€ ์ž์‹์€ ๊ณต์กดํ•˜๋ฉฐ ์ˆ˜ํ–‰๋˜๋Š” ๋ชจ๋ธ
  • ์ž์‹์ด ์ข…๋ฃŒ (terminate) ๋  ๋•Œ๊นŒ์ง€ ๋ถ€๋ชจ๊ฐ€ ๊ธฐ๋‹ค๋ฆฌ๋Š”(wait) ๋ชจ๋ธ

โœ”๏ธ ์ฃผ์†Œ ๊ณต๊ฐ„

  • ์ž์‹์€ ๋ถ€๋ชจ์˜ ๊ณต๊ฐ„์„ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌํ•œ๋‹ค (binary and OS data)
  • ์ž์‹์€ ๊ทธ ๊ณต๊ฐ„์— ์ƒˆ๋กœ์šด ํ”„๋กœ๊ทธ๋žจ์„ ์˜ฌ๋ฆผ

Termination

โœ”๏ธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋งˆ์ง€๋ง‰ ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•œ ํ›„ ์šด์˜์ฒด์ œ์—๊ฒŒ ์ด๋ฅผ ์•Œ๋ ค์คŒ exit()

  • ์ž์‹์ด ๋ถ€๋ชจ์—๊ฒŒ output data๋ฅผ ๋ณด๋ƒ„
  • ํ”„๋กœ์„ธ์Šค์˜ ๊ฐ์ข… ์ž์›๋“ค์ด OS์— ๋ฐ˜๋‚ฉ๋จ

โœ”๏ธ ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ž์‹์˜ ์ˆ˜ํ–‰์„ ์ข…๋ฃŒ์‹œํ‚ด abort

  • ์ž์‹์ด ํ• ๋‹น ์ž์›์˜ ํ•œ๊ณ„์น˜๋ฅผ ๋„˜์–ด์„ฌ
  • ์ž์‹์—๊ฒŒ ํ• ๋‹น๋œ ํƒœ์Šคํฌ๊ฐ€ ๋” ์ด์ƒ ํ•„์š”ํ•˜์ง€ ์•Š์Œ
  • ๋ถ€๋ชจ๊ฐ€ ๋จผ์ € ์ข…๋ฃŒ?
    • ์šด์˜์ฒด์ œ๋Š” ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒํ•˜๋Š” ๊ฒฝ์šฐ ์ž์‹์ด ๋” ์ด์ƒ ์ˆ˜ํ–‰๋˜๋„๋ก ๋‘์ง€ ์•Š๋Š”๋‹ค
    • ๋‹จ๊ณ„์  ์ข…๋ฃŒ

PCB

โœ”๏ธ ์šด์˜์ฒด์ œ๊ฐ€ ๊ฐ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ์„ธ์Šค๋‹น ์œ ์ง€ํ•˜๋Š” ์ •๋ณด๋กœ,
โœ”๏ธ ๊ตฌ์กฐ์ฒด๋กœ ์œ ์ง€๋œ๋‹ค

1) OS๊ฐ€ ๊ด€๋ฆฌ์ƒ ์‚ฌ์šฉํ•˜๋Š” ์ •๋ณด

  • Process state, Process ID
  • Scheduling Information, Priority

2) CPU ์ˆ˜ํ–‰ ๊ด€๋ จ ํ•˜๋“œ์›จ์–ด ๊ฐ’

  • Program Counter, Registers

3) Memory ๊ด€๋ จ

  • Code, Data, Stack ์˜ ์œ„์น˜ ์ •๋ณด

4) File ๊ด€๋ จ

  • Open File Desciptors...

process control block also called a task control block

๊ตฌ์„ฑ

identification

  • process id
  • OS์˜ root process ๋ฅผ ์ œ์™ธํ•˜๋ฉด parent process์˜ id๋ฅผ ๊ฐ€์ง„๋‹ค. (tree ๊ตฌ์กฐ์ฒ˜๋Ÿผ)
  • User id

processor state information

  • user visible register
  • control and state register
    - program counter, condition codes, status information
  • stack pointers

IPC; Inter-Process Comumunication

  • signal : process ๊ฐ„ ์†Œํ†ตํ•˜๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜
  • terminate (to kill), communicate (to send message) block ํ•  ์ˆ˜ ์žˆ๊ณ  ์—ฌ๋Ÿฌ flag๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค

(... ๊ต์žฌ ์ฐธ๊ณ )
Program counter.
The counter indicates the address of the next instruction to be executed for this process.

CPU registers.
The registers vary in number and type, depending on the computer architecture. They include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-code informa- tion. Along with the program counter, this state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward when it is rescheduled to run.

CPU-scheduling information.
This information includes a process prior- ity, pointers to scheduling queues, and any other scheduling parameters. (Chapter 5 describes process scheduling.)

Memory-management information.
This information may include such items as the value of the base and limit registers and the page tables, or the segment tables, depending on the memory system used by the operating system (Chapter 9).

Accounting information.
This information includes the amount of CPU and real time used, time limits, account numbers, job or process numbers, and so on.

I/O status information.
This information includes the list of I/O devices allocated to the process, a list of open files, and so on.


PSW

program status word
ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค์˜ ์Šคํ…Œ์ดํŠธ ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.

โœ”๏ธ contatins condition codes and other status information of the currently running process
โœ”๏ธ ex) EEFLAGS register on Intel x86 processors


Process control

Process spawing

  • OS may create a process at the explicit request of another process

Process termination

  • A process may terminate itself by calling a system call called EXIT
  • A process may terminate due to an erroneous condition such as memory unavailable, arithmetic error (overflow), or parent process termination, etc.

System Call

์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด ์šด์˜์ฒด์ œ์˜ ์„œ๋น„์Šค๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด ์ปค๋„ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ

  • Unix provides a number of system calls for manipulating processes
  • Obtain process ID, Create/Terminate Process, etc.

fork

system call fork ์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์ž

int fork (void)
โœ”๏ธ Creates a new process (child process) that is identical to the calling process (parent process)
โœ”๏ธ Returns 0 to the child process
โœ”๏ธ Returns child's pid to the parent process
โœ”๏ธ It is called once but returns twice. ์ฒ˜์Œ ์ถœ๋ฐœ์€ ๊ฐ™์œผ๋‚˜, ๊ฐ๊ฐ์˜ ๋…๋ฆฝ์ ์ธ VM์„ ๊ฐ€์ง€๊ณ  ๊ฐ์ž ์‹คํ–‰๋œ๋‹ค.
โœ”๏ธ ๋ˆ„๊ฐ€ ๋จผ์ € ์‹คํ–‰๋ ์ง€๋Š” undefined! ์Šค์ผ€์ค„๋ง์— ๋”ฐ๋ผ ๋•Œ๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค.
โœ”๏ธ Shared files : oth parent and child print their output on the same screen

exit

void exit(int status)
โœ”๏ธ Terminate a process with an exit status : Normally with status 0
โœ”๏ธ atexit() registers functions to be executed upon exit


Five-State Process Model

ํ”„๋กœ์„ธ์Šค๋Š” State๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉฐ ์ˆ˜ํ–‰๋œ๋‹ค
โœ”๏ธ Running

  • CPU๋ฅผ ์žก๊ณ  instruction์„ ์ˆ˜ํ–‰์ค‘์ธ ์ƒํƒœ

โœ”๏ธ Ready

  • CPU๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํƒœ (๋ฉ”๋ชจ๋ฆฌ ๋“ฑ ๋‹ค๋ฅธ ์กฐ๊ฑด์„ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๊ณ )

โœ”๏ธ Blocked(wait, sleep)

  • CPU๋ฅผ ์ฃผ์–ด๋„ ๋‹น์žฅ instruction ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†๋Š” ์ƒํƒœ
  • Process ์ž์‹ ์ด ์š”์ฒญํ•œ event ๊ฐ€ ์ฆ‰์‹œ ๋งŒ์กฑ๋˜์ง€ ์•Š์•„ ์ด๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํƒœ
  • ๋””์Šคํฌ์—์„œ file์„ ์ฝ์–ด์™€์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ

โœ”๏ธ New

  • ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ƒ์„ฑ์ค‘์ธ ์ƒํƒœ

โœ”๏ธ Terminated

  • execution ์ด ๋๋‚œ ์ƒํƒœ


(unix ์—์„œ๋Š” terminated ์ƒํƒœ๋ฅผ zombie ์ƒํƒœ๋ผ๊ณ  ํ•œ๋‹ค)

using mutiple blocked queues


event ๋งˆ๋‹ค queue ๊ฐ€ ์กด์žฌํ•œ๋‹ค.


Suspended Processes

โœ”๏ธ ์™ธ๋ถ€์ ์ธ ์ด์œ ๋กœ ํ”„๋กœ์„ธ์Šค์˜ ์ˆ˜ํ–‰์ด ์ •์ง€๋œ ์ƒํƒœ
โœ”๏ธ ํ”„๋กœ์„ธ์Šค๋Š” ํ†ต์งธ๋กœ ๋””์Šคํฌ์— Swap out ๋œ๋‹ค

  • ex) ์‚ฌ์šฉ์ž๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์„ ์ผ์‹œ ์ •์ง€์‹œํ‚จ ๊ฒฝ์šฐ ๋˜๋Š” ์‹œ์Šคํ…œ์ด ์—ฌ๋Ÿฌ ์ด์œ ๋กœ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ž ์‹œ ์ค‘๋‹จ์‹œํ‚ด

โ—๏ธ Blocked vs. Suspended

  • Blocked : ์ž์‹ ์ด ์š”์ฒญํ•œ event ๊ฐ€ ๋งŒ์กฑ๋˜๋ฉด Ready
  • Suspended(stopped) : ์™ธ๋ถ€์—์„œ resume ํ•ด์ฃผ์–ด์•ผ Active

๋ฉ”๋ชจ๋ฆฌ๋กœ๋ถ€ํ„ฐ ์ซ“๊ฒจ๋‚˜์„œ ์‹คํ–‰ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ์ง€ ์•Š๋Š” ํ”„๋กœ์„ธ์Šค๋“ค์ด๋‹ค. page-fault (page-miss) ๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ๋‹ค.

Swapping

  • Sometimes, all the processes in memory are waiting for I/O
  • Involves moving part or all of a process from main memory to disk
  • Then, OS brings in another (new or suspended) process into memory

Suspended Process

  • The process is swapped out and is not immediately available for execution
  • The process was placed in a suspended state by an agent: either itself, a parent process, or the OS, for the purpose of preventing its execution
  • The process may or may not be waiting on an event

suspend state ๐ŸŽฏ

์ด๋ฅผ ๊ณ ๋ คํ•˜๋ฉด State ๊ฐ€ ๋ฐ”๋€๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์ด ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ state model ์ด๋‹ค.

์ด๋ฏธ์ง€ ์ถœ์ฒ˜


Interrupt/Exception

์ธํ„ฐ๋ŸฝํŠธ ๋‹นํ•œ ์‹œ์ ์˜ ๋ ˆ์ง€์Šคํ„ฐ์™€ program counter ๋ฅผ saveํ•œ ํ›„ CPU์˜ ์ œ์–ด๋ฅผ ์ธํ„ฐ๋ŸฝํŠธ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด์— ๋„˜๊ธด๋‹ค.

โœ”๏ธ Interrupt (ํ•˜๋“œ์›จ์–ด ์ธํ„ฐ๋ŸฝํŠธ) : ํ•˜๋“œ์›จ์–ด๊ฐ€ ๋ฐœ์ƒ์‹œํ‚จ ์ธํ„ฐ๋ŸฝํŠธ (๋””์Šคํฌ ์ปจํŠธ๋กค๋Ÿฌ, ํƒ€์ด๋จธ ๋“ฑ)

โœ”๏ธ Trap (์†Œํ”„ํŠธ์›จ์–ด ์ธํ„ฐ๋ŸฝํŠธ) :

  • Exception : ํ”„๋กœ๊ทธ๋žจ์ด ์˜ค๋ฅ˜๋ฅผ ๋ฒ”ํ•œ ๊ฒฝ์šฐ
  • System Call : ํ”„๋กœ๊ทธ๋žจ์ด ์ปค๋„ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ

โœ”๏ธ ๊ด€๋ จ ์šฉ์–ด

  • ์ธํ„ฐ๋ŸฝํŠธ ๋ฒกํ„ฐ
    • ํ•ด๋‹น ์ธํ„ฐ๋ŸฝํŠธ์˜ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง
  • ์ธํ„ฐ๋ŸฝํŠธ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด (Interrupt Service Routine, ์ธํ„ฐ๋ŸฝํŠธ ํ•ธ๋“ค๋Ÿฌ)
    • ํ•ด๋‹น ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ปค๋„ ํ•จ์ˆ˜

Kernel ๋กœ ๋“ค์–ด๊ฐ€๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์‹คํ–‰ ์ค‘์ด๋˜ ํ”„๋กœ์„ธ์Šค๋Š” register state ๊ฐ€ pcb ์— ์ €์žฅ๋˜๊ณ  suspended (swap ์ด ์•„๋‹ˆ pause ์˜ ์ด๋ฏธ) ๋œ๋‹ค.

Exception, Interrupt ๋Š” ๋ฉ”์นด๋‹ˆ์ฆ˜์€ ๋น„์Šทํ•˜๋‚˜ ๋ฐœ์ƒ ์›์ธ์ด ๋‹ค๋ฅด๋‹ค.

Interrupts

  • Exception : ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค์—์„œ ํŠน์ • ๋ช…๋ น์–ด์— ์˜ํ•ด ๋ฐœ์ƒํ•œ ์˜ˆ์™ธ ์ƒํ™ฉ์ธ๋ฐ, CPU๊ฐ€ ๋” ์ด์ƒ ํ•ธ๋“คํ•  ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ
    • Generated by an instruction in the currently running process due to an erroneous condition.
    • Synchronous, internal
    • ex) page faults (page miss)
  • Interrupt : ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค์˜ ๋ฌธ์ œ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์ฆ‰, CPU ๋‚ด๋ถ€์™€ ์ƒ๊ด€์ด ์—†๋Š” ๊ฒฝ์šฐ
    • Asynchronous, external events
    • ex) ์šฐ๋ฆฌ๊ฐ€ ๋ฆฌ๋ถ€ํŠธํ•˜๋Š” ๊ฒฝ์šฐ, ๋””์Šคํฌ๊ฐ€ CPU์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์„ธ์ง€, ๊ฐ‘์ž๊ธฐ ๋…ธํŠธ๋ถ์ด ๊บผ์ง€๋Š” ๊ฒฝ์šฐ, ๋กœ๋ด‡์ด ๊ธธ์„ ๊ฑท๋‹ค๊ฐ€ ๋Œ์„ ๋งž๋Š” ๊ฒฝ์šฐ ๋“ฑ

CPU ๋Š” Clock Cycle (0.3 nano seconds) ๋งˆ๋‹ค ์™ธ๋ถ€ Interrupt ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ณ  ์žˆ๋‹ค๋ฉด ์ฒ˜๋ฆฌํ•˜๊ณ  ๋‹ค์‹œ ๋Œ์•„์˜จ๋‹ค.

CPU ์นฉ ๋‚ด๋ถ€ pin ์ค‘ ํ•˜๋‚˜๊ฐ€ interrupt pin ์—๊ฒŒ ์‹ ํ˜ธ๊ฐ€ ์ „์†ก๋œ๋‹ค. pin ์ด assault ๋˜์—ˆ๋‹ค๋ฉด system bus io device ๊ฐ€ ์–ด๋–ค ์ด๋ฒคํŠธ์ธ์ง€ ์•Œ๋ ค์ค€๋‹ค.

๋ชจ๋“  ์ด๋ฒคํŠธ๋งˆ๋‹ค (id ๊ฐ€ ์žˆ๋‹ค) Interrupt Handler (์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ) ๊ฐ€ ์‹œ์Šคํ…œ์— ์ •์˜๋˜์–ด ์žˆ๋‹ค. ์ด ํ•ธ๋“ค๋Ÿฌ ์ฝ”๋“œ๋Š” OS ์ฝ”๋“œ๊ฐ€ ์•„๋‹Œ firmware ์ด๋‹ค! ๊ทธ๋“ค์ด System call ์„ ํ†ตํ•ด ํ•„์š”ํ•œ OS ๋ฅผ ์—ฐ๊ฒฐ์‹œ์ผœ์ค€๋‹ค.

Interrupt handling mechanism
Should allow interrupts/exceptions to be handled transparently to the executing process

  • When an interrupt is received or an exception condition is detected, the current task is suspended(paused) and the control automatically transfers to a handler.
  • After the handler is complete, the interrupted task resumes without loss of continuity, unless recovery is not possible or the interrupt causes the currently running task to be terminated.

(Synchronous) Exceptions

Caused by an event that occurs as a result of executing an instruction.

โœ”๏ธ Traps
: ๋ช…๋ น์„ ์™„๋ฃŒํ•œ ํ›„ ์˜๋„์ ์œผ๋กœ ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ์‹คํ–‰๋˜๊ณ  ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค.

  • Intentional exceptions
  • ex) system calls, breakpoints (debug)
  • Returns control to next instruction

โœ”๏ธ Faults
: ๋ช…๋ น์–ด ์‹คํ–‰์„ ์™„๋ฃŒํ•˜์ง€ ๋ชปํ•œ ์ƒํ™ฉ. ์ค‘์ง€ ํ›„ fault ๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ ๋ช…๋ น์–ด๋ถ€ํ„ฐ ๋‚˜์ค‘์— ๋‹ค์‹œ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค.

  • Unintentional but possibly recoverable
  • ex) page faults (recoverable), protection faults (unrecoverable)
  • Either re-executes faulting ("current") instruction or terminate the process

โœ”๏ธ Aborts
: ์‹ฌ๊ฐํ•œ ํ•˜๋“œ์›จ์–ด์  ์—๋Ÿฌ์ด๋‹ค.

  • Unintentional and Unrecoverable fatal errors
  • ex) parity error, machine check abort
  • Aborts the current process, and probably the entire system

(Asynchronous) Interrupts

Caused by an event external to the processor

  • Handler returns to "next" instruction.
  • ex) I/O interrupts

I/O

๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ ๋ชจ๋‘ I/O์˜ ์™„๋ฃŒ๋Š” ์ธํ„ฐ๋ŸฝํŠธ๋กœ ์•Œ๋ ค์ค€๋‹ค

Synchronous I/O

I/O ์š”์ฒญ ํ›„ ์ž…์ถœ๋ ฅ ์ž‘์—…์ด ์™„๋ฃŒ๋œ ํ›„์—์•ผ ์ œ์–ด๊ฐ€ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์— ๋„˜์–ด๊ฐ

Asychronous I/O

I/O๊ฐ€ ์‹œ์ž‘๋œ ํ›„ ์ž…์ถœ๋ ฅ ์ž‘์—…์ด ๋๋‚˜๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ์ œ์–ด๊ฐ€ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์— ์ฆ‰์‹œ ๋„˜์–ด๊ฐ


๐Ÿ”— Reference

[KUOCW] ๋ฐ˜ํšจ๊ฒฝ ๊ต์ˆ˜๋‹˜, ์ตœ๋ฆฐ ๊ต์ˆ˜๋‹˜์˜ ์šด์˜์ฒด์ œ ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•˜๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์ž˜๋ชป๋œ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š

0๊ฐœ์˜ ๋Œ“๊ธ€