๐ ๊ณต๋ฃก์ฑ ๊ธฐ๋ฐ์ผ๋ก ํ๊ต์์ ์์ ํ๋ ์ด์์ฒด์ ๋ฅผ ์ ๋ฆฌํฉ๋๋ค.
1๏ธโฃ Process
- ์ ์ : ์คํ์ค์ธ ํ๋ก๊ทธ๋จ
- ํ๋ก๊ทธ๋จ : passive entity, ์คํํ์ง ์์ ์ํ์ ์คํ ํ์ผ(instruction๋ค)
- ํ๋ก์ธ์ค : active entity, ์คํ ์์ฒญํด์ ์คํ์ค์ธ ํ๋ก๊ทธ๋จ
- ์คํ์ค → ํ๋ก๊ทธ๋จ ์นด์ดํฐ(pc)๊ฐ ๋ค์ instruction๊ณผ resource์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๊ณ ์๋ค.
- ํ๋ก๊ทธ๋จ ์นด์ดํฐ : ์งํ ์ํฉ ๊ธฐ๋กํ๋ ์ญํ . ๋ค์์ ์ด๋ค instruction์ธ์ง ์ ์ฅํ๋ค.
- ๋ฆฌ์์ค : ์ค์ ํ๋ก๊ทธ๋จ์ด ๋์๊ฐ๋ ์ค์ ์ฌ์ฉ์ค์ธ ํ์ผ, open files ๋ฑ
โ๏ธ ๊ทธ๋ฆผ์ผ๋ก ์์๋ณด๋ ํ๋ก์ธ์ค ๊ณผ์

- Disk
- Program = binary file with machine instructions
- Main Memory
- Program Code : ํ๋ก๊ทธ๋จ → ํ๋ก์ธ์ค๊ฐ ๋๋ ค๋ฉด CPU๊ฐ ์ฝ์ด์ ์ฒ๋ฆฌํ ์ ์๋๋ก ํ๋ก๊ทธ๋จ ์ฝ๋๊ฐ ๋ฉ์ธ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ผ๊ฐ ์์ด์ผ ํ๋ค.
- Byte Array : ๋ฉ์ธ ๋ฉ๋ชจ๋ฆฌ์์๋ Byte Array ๋ฐฉ์์ผ๋ก ํ๋ก๊ทธ๋จ ์ฝ๋๊ฐ ์ ์ฅ๋์ด ์๋ค. = ๋ฐ์ดํธ๋ง๋ค ์ฃผ์๊ฐ ๋ถ์ด์๋ค. ๋ฐ์ดํธ ๋จ์๋ก ์ฃผ์๋ฅผ ์ฐธ์กฐ. ๊ฐ ์ฃผ์๋ง๋ค 8๋นํธ(= 1byte)์ ๋ฐ์ดํฐ ์ ์ฅ
- CPU
- Cache : ๋ฉ์ธ ๋ฉ๋ชจ๋ฆฌ(addr)์ ์๋ ๋ฐ์ดํฐ๋ฅผ ๋ฏธ๋ฆฌ cache์ copy ํด๋๋ค.
- Registers : ์๋(word)๋ผ๋ ๋จ์(๋ณดํต 2๋ฐ์ดํธ = 16bits)๋ก ์ฝ์ด์์ ์์๋ก ์ ์ฅํ๋ค.
- ALU : Arithmetic Logit Unit. ๋ ผ๋ฆฌ ์ฐ์ฐ ๊ณ์ฐ
2๏ธโฃ Process in Memory
- ๋ฉ๋ชจ๋ฆฌ์๋ ํ๋์จ์ด instruction ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๊ฒ๋ค๋ ์ฌ๋ผ๊ฐ๋ค

โ๏ธ ๊ณ ์ ๋ ํฌ๊ธฐ
- Text : ํ๋ก๊ทธ๋จ ์ฝ๋. read-only
- binary. ์ ์ผ ์๋ ๋ถ๋ถ. ํ๋ก๊ทธ๋จ์ ์คํํ๋ฉด์ ๋ฐ๋์ง ์๋ ๋ถ๋ถ. ์ฝ๋๋ ํ ๋ฒ ์ปดํ์ผํ๋ฉด ๋ฐ๋์ง ์์. ๋ค์ ์ปดํ์ผ ํ์ง ์๋ ์ด์ read-only. → ํ๋ก์ธ์ค๋ฅผ ์คํ์ค์ธ๋ฐ ํ๋ก๊ทธ๋จ์ด ๋ฐ๋๋ฉด ์ ๋๋๊น ๋น์ฐํ read-only ๋ก ๋ณดํธ๋์ด์ผ ํ๋ค.
- Data : ์ ์ญ ๋ณ์
โ๏ธ ๊ณ ์ ๋ ํฌ๊ธฐ X
- Stack : ์ง์ญ ๋ณ์, parameter, return address of function
- ์ง์ญ ๋ณ์
- ํจ์๋ฅผ ํธ์ถ ํ์ ๋ parameter
- ํจ์์ ๋ฐํ ์ฃผ์ : ํจ์๋ฅผ ํธ์ถํ๋ฉด, ํจ์ ๋ถ๋ถ์ ์ฝ๋๋ก ์ ํํ๊ณ , ๋ฆฌํดํ๋ฉด ๋ค์ ์๋์ ํจ์๋ก ( ex - ์๋ฅผ ๋ค๋ฉด main์์ add๋ฅผ ํธ์ถํ๋ฉด pc๊ฐ add๋ก jumpํด์ ์คํํ๊ณ return์ ํ๋ฉด ๋ค์ ์๋ ์คํํ๋ main์ผ๋ก ๋์๊ฐ๊ธฐ ์ํด์ return address๋ฅผ ์ ์ฅํ๊ณ ์์ด์ผ ํ๋ค )
- stack frame : ํจ์๋ฅผ ํธ์ถํ๋ฉด ํจ์๊ฐ ์ธ ์ ์๋ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ด ํ ๋น๋๋๋ฐ ๊ทธ๊ฒ์ stack frame์ด๋ผ๊ณ ํ๋ค.
- ํจ์๋ฅผ ํธ์ถํ ๋ ์คํ์ด ๋์ด๋๋ค๊ฐ, ํจ์๊ฐ ๋ฐํ๋๋ฉด ์คํ์ด ์ค์ด๋ ๋ค → ์คํ์ ์ปค์ก๋ค ์์์ก๋ค ํ ์ ์๋ค.
- Heap : ์ถ๊ฐ์ ์ผ๋ก ๊ณต๊ฐ์ ํ ๋นํ ๋. ๋์ ํ ๋น(malloc, free)
์์ )

- text : ์ปดํ์ผ๋ binary ํํ๋ก ํ๋ก๊ทธ๋จ ์ฝ๋๊ฐ ๋ค์ด๊ฐ ์๋ค.
- data : ์ด๊ธฐํ๋ ๋ณ์(x)์, ์ด๊ธฐํ๊ฐ ๋์ง ์์ ๋ณ์(y)๊ฐ ๋๋์ด์ ธ์ ์ ์ญ ๋ณ์๊ฐ ์ ์ฅ๋๋ค.
- heap : malloc ํจ์๋ฅผ ํตํด ๋์ ์ผ๋ก ํ ๋น๋ ๋ฒํผ(values)๊ฐ ์ ์ฅ๋๋ค.
- stack : main ํจ์์๊ฒ ํ ๋น๋ stack frame์์ ์ง์ญ ๋ณ์(*values, i)์ ํ๋ผ๋ฏธํฐ ๋ฑ์ด ์ ์ฅ๋๋ค.
- high memory : command line argument๋ค์ด argc, argv์ ์ ์ฅ๋๋ค.
- ๊ทธ ์ : kernel์ด ์ฌ์ฉํ๋ ๋ถ๋ถ
3๏ธโฃ Process State
- ํ๋ก์ธ์ค์ ์ํ๋ฅผ OS๊ฐ ๊ด๋ฆฌํด์ค์ผ ํ๋ค.
- ๊ทธ ์ข ๋ฅ๋ OS์ ์ข ๋ฅ์ ๋ฐ๋ผ ๋ค๋ฅด๋ค. OS-dependent
- ์ธ์ ์ํ๊ฐ ๋ฐ๋๋์ง ์๊ณ ์์ด์ผ ํ๋ค.

- New : ํ๋ก์ธ์ค๊ฐ ๋ง๋ค์ด์ ธ์ ์์คํ ์ ๋ค์ด์๊ณ , ์คํ๋๋ ค๋ฉด ํ๋ก์ธ์๋ฅผ ๋ฐ์์ผ ํ๋ค. ์์ง ํ๋ก์ธ์ ๋ชป ๋ฐ์
- Ready : ํ๋ก์ธ์๊ฐ ์์ด์ ๊ธฐ๋ค๋ฆฌ๊ณ ์๋ ์ํ. ํ๋ก์ธ์ค๊ฐ ํ๋ก์ธ์ ํ ๋น ๋ฐ๊ธฐ ๊ธฐ๋ค๋ฆฌ๋ ์ํ
- Running : Scheduler๊ฐ ์ ํ๋์ด์, ํ๋ก์ธ์๊ฐ ๋์๊ฐ๋ ์ํ (์ฑ๊ธ ์ฝ์ด๋ผ๋ฉด running์ด 1๊ฐ ๋ฟ)
- waiting : ํ์ผ์ ๋์คํฌ์์ ์ฝ์ด์ฌ ๋, I/O ๋ฑ๋ฑ ๊ธฐ๋ค๋ฆด ๋
- terminated : ํ๋ก์ธ์๊ฐ ์ต์ข ์ ์ผ๋ก exit
4๏ธโฃ Process Control Block (PCB)
- state๋ฅผ ์ ์ฅํ๊ธฐ ์ํ stucture(๊ตฌ์กฐ). OS๊ฐ ํ๋ก์ธ์ค๋ง๋ค PCB๋ฅผ ๊ด๋ฆฌ.
- ํ๋ก์ธ์ค์ ๋ํ ์ ๋ณด ์ ์ฅํ๊ธฐ ์ํ data structrue (representation of a process)
- Kernel์ด ๊ด๋ฆฌํ๋ ๋ฉ๋ชจ๋ฆฌ → ํ๋ก์ธ์ค๊ฐ ๊ด๋ฆฌํ๋ ๋ฉ์ธ ๋ฉ๋ชจ๋ฆฌ์ ์์ชฝ์ ์์นํ๊ณ ์๋ค. ์๋ฌด๋ ์ ๊ทผ ๋ถ๊ฐ๋ฅ.
- ํ๋ก์ธ์ค์ ๊ฐ์์ ๋ง๊ฒ PCB๊ฐ ์๋ค.

- process state : ํ๋ก์ธ์ค ์ํ (running, waiting ...)
- process number : pid, ํ๋ก์ธ์ค ์๋ณ์
- program counter : ์งํ ์ํฉ ๊ธฐ๋ก. ํ๋ก์ธ์ค๋ฅผ ์ํด ์คํ๋ ๋ค์ ๋ช ๋ น์ด(instruction)์ ์ฃผ์๋ฅผ ์ ์ฅํ๋ค
- registers : register๊ฐ ์๋ค๋ ๊ฒ์ด ์๋๋ผ, register์ ๊ฐ์ ์ ์ฅํ๋ ๊ฒ์ด๋ค. register ๊ฐ์ด ๊ณ์ ์๋ฐ์ดํธ ๋ ํ ๋ฐ, ๊ทธ ๊ฐ๋ค์ backupํด๋๋ค๊ณ ์๊ฐํ๋ฉด ๋๋ค.
- memory limits : ๋ฉ๋ชจ๋ฆฌ ์ผ๋ง๋ ์ธ ์ ์๋์ง (os์ ์ํด ์ฌ์ฉ๋ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ์์คํ ์ ๋ณด - page table, segment table ๋ฑ)
- list of open files : ์ด๋ฆฐ ํ์ผ ๋ชฉ๋ก ( ์ด๊ฒ ์ธ์๋ ํ๋ก์ธ์ค์๊ฒ ํ ๋น๋ I/O ๋๋ฐ์ด์ค ๋ชฉ๋ก๋ค์ด PCB ์ ์ฅ๋๋ค. )
- ๊ทธ ์ธ์๋ CPU ์ค์ผ์ค๋ง ์ ๋ณด(ํ๋ก์ธ์ค์ ์ฐ์ ์์) ๋ฑ ๋ง์ ์ ๋ณด๊ฐ ์ ์ฅ๋๋ค
5๏ธโฃ Process Scheduling

- ์์ฒญ ๋ง์ ํ๋ก์ธ์ค → ์ค์ผ์ค๋ง ์ญํ ๋ ์ค์
- ์ด๋ค CPU ์ฝ์ด์ ์ด๋ค ํ๋ก์ธ์ค๋ฅผ ์คํ์ํฌ์ง ๊ฒฐ์ ํด์ค๋ค.
- ์ต๋ํ CPU๋ฅผ ํ์ฉํด์ ๋ญ๋น๋๋ ์๊ฐ์ด ์๋๋ก ํ๋ ๊ฒ์ด ์ฃผ์ ๋ชฉํ
- ํ(Queue)๋ฅผ ํ์ฉํ ์ค์ผ์ฅด๋ง
- ํ๋ก์ธ์ค ํ ๋น์ ํ ์์ ๋ง๊ณ , ์๊ณ ๋ฆฌ์ฆ์ด ์์์
- wait queue๋ ์ํฉ์ ๋ง๊ฒ ์ฌ๋ฌ๊ฐ ์์ ์ ์๋ค.
- wait queue์์ ๋์ค๋ฉด ready queue๋ก ๊ฐ๋ค.
- Ready queue : 1๊ฐ
- Wait queues : ์ฌ๋ฌ๊ฐ
- Queuing Diagram
- ํ๋ก์ธ์ค๊ฐ ์์คํ ์ ๋ค์ด๊ฐ๋ฉด, Ready queue์ ๋ค์ด๊ฐ์ CPU ์ฝ์ด์์ ์คํ๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฐ๋ค. (์ฐ๊ฒฐ ๋ฆฌ์คํธ์ PCB ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ ์ ์ฅ)
- ์ฝ์ด๊ฐ ํ ๋น๋์ด์ ํ๋ก์ธ์ค๋ฅผ ์คํ
- → I/O ์์ฒญ์ ๋ํ ๋๊ธฐ, child ํ๋ก์ธ์ค์ ์ข ๋ฃ ๋๊ธฐ, interrupt๋ก ์ธํ ๋๊ธฐ ๋ฑ์ผ๋ก ์ธํด์ waiting queue์์ ๋๊ธฐ
- → I/O, child ํ๋ก์ธ์ค ์ข
๋ฃ, interrupt ๋ฐ์ ์ดํ ๋ค์ Ready queue๋ก ๋์์๊ฒ ๋๋ค.

6๏ธโฃ Context Switch โญ๏ธ

- Context Switch = CPU๊ฐ ์ด๋ค ํ๋ก์ธ์ค๋ฅผ ์ํํ๋ค๊ฐ ๋ค๋ฅธ ํ๋ก์ธ์ค๋ก ๋์ด๊ฐ๋ ๊ฒ
- Old Process : P0์ ์ค๋จ ํ๊ธฐ ์ํด, P0์ PCB์ ์คํ ์ค์ธ ์ ๋ณด๋ฅผ ์ ์ฅ (→ save the architectural state )
- New Process : P1์ด ์์ ์ ์คํ๋์๋ ๋ฐ์ดํฐ๋ฅผ PCB์์ ๋ถ๋ฌ์จ๋ค. (→ load the saved state )
์ด๋ค ๊ฒ์ ๋ฐฑ์ ?
- Context : Program Counter + Registers
- pure overhead ; ๊ด๋ฆฌ๋ฅผ ์ํด ๋๋ ์ถ๊ฐ cost.
- OS๊ฐ PCB๋ฅผ ์ ๊ด๋ฆฌํ๊ธฐ ์ํด ์ ๋ณด๋ฅผ ์ถ๊ฐ๋ก ์ ์ฅ → ์ํ ์ ํ์ด ๋ ๋น ๋ฅด๊ฒ

cf. ์ฌํ) Time dependent on hardware support

- ์ปจํ ์คํธ ์ค์์น ๊ฐ์ด hw support์ ๋ฐ๋ผ ๋ค๋ฅด๋ค.→ ๋ถ๋ฌ์๋ค๊ฐ ๋ค์ ์ ์ฅํ ํ์ ์์ด, ํ๋ก์ธ์ค ์์์ ์๋ค๊ฐ๋ค
- → hyperthreading
- → ํ CPU์ ์ฌ๋ฌ๊ฐ์ Register๋ฅผ ์ ๊ณต = ์ฌ๋ฌ๊ฐ Context๋ฅผ ํ๋ฒ์ ๋ก๋ ๊ฐ๋ฅ
- ๊ฐ ์ฝ์ด๊ฐ ๋ ๊ฐ ์ด์์ ์ฐ๋ ๋๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ค๊ณ ์ฌ๊ธด๋ค
- → Logical(virtual) cores (↔ physical cores )
7๏ธโฃ Operations on Processes : Process Creation

- ์์ฑํ๋ ๋ฐฉ์ : Parent ํ๋ก์ธ์ค → child ํ๋ก์ธ์ค
- ๋ฆฌ๋
์ค PCB ๊ตฌ์กฐ์ฒด๋ฅผ ๋ณด๋ฉด
parent๋ผ๋ ํฌ์ธํฐ๊ฐ ์์ด์ ๋ถ๋ชจ ํ๋ก์ธ์ค์ PCB๋ฅผ ๊ฐ๋ฆฌํค๊ณ ์๋ค. - pid(process identifier)๋ฅผ ํตํด ํ๋ก์ธ์ค๋ฅผ ๊ตฌ๋ถ. ์์์ ๋ถ๋ชจ ํ๋ก์ธ์ค์ pid ๊ฐ์ ์ ์ฅํ๊ณ ์๋ค.
- ๋ฆฌ๋
์ค PCB ๊ตฌ์กฐ์ฒด๋ฅผ ๋ณด๋ฉด
- ์์ฑ, ๊ด๋ฆฌ ๋ฐฉ๋ฒ์ OS ๋ง๋ค ๋ค๋ฅด๋ค → ๋ค์ํ ์ต์
์ด ์๋ค.
- Resource Sharing - ์ ๋ถ, ์ผ๋ถ, ์์
- Execution - ๋์์(๊ฐ์ด), ๋ถ๋ชจ๊ฐ …
- Address space - ๋ณต์ , ์์ฒด ํ๋ก๊ทธ๋จ
๐ Example
fork(): ์ ํ๋ก์ธ์ค ์์ฑํ๋ system callexec(): fork ์ดํ ํ๋ก์ธ์ค ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ ์ ํ๋ก๊ทธ๋จ์ผ๋ก ๋ฐ๊ฟ์ฃผ๋ system callwait(): parent ํ๋ก์ธ์ค๊ฐ child ํ๋ก์ธ์ค์ ์ข ๋ฃ๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ธฐ ์ํด ์ฌ์ฉํ๋ system call- code example

8๏ธโฃ Operations on Processes : Process Termination
๐ exit()
exit(): ํ๋ก์ธ์ค๊ฐ ๋ง์ง๋ง ๋ช ๋ น์ ์ํํ ํ OS์๊ฒ ์ข ๋ฃ๋ฅผ ์๋ ค์ฃผ๋ System call- exit()์ด ๋๋ฉด
- ์์์ด ๋ถ๋ชจ์๊ฒ output data๋ฅผ ๋ณด๋ธ๋ค. (→child๊ฐ ๋๋ฌ๋์ง๋ฅผ wait()๋ฅผ ํตํด ์ ์ ์๋ค.)
- ํ๋ก์ธ์ค์ ๋ฆฌ์์ค๋ค์ด OS์ ์ํด deallocated(๋ฐ๋ฉ) ๋๋ค.
- child๊ฐ exit๋๋ฉด terminated ์ํ๊ฐ ๋๊ณ , ์ด๊ฒ์ด system call๋ก parent๋ก ์ ๋ฌ๋๋ฉด, wait์ด์๋ parent๋ ๋ค์ ready ์ํ๊ฐ ๋๋ค.
- exit()์ด ๋๋ฉด

๐ abort()
abort(): ํ๋ก์ธ์ค๋ฅผ ๊ฐ์ ์ข ๋ฃํด์ฃผ๋ system call- ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์์ ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃ์ํค๋ 3๊ฐ์ง ๊ฒฝ์ฐ
- ๋ฆฌ์์ค๋ฅผ ๋๋ฌด ๋ง์ด ์ฐ๋ฉด(ํ ๋น ๋ฆฌ์์ค๋ฅผ ์ด๊ณผ)
- child์๊ฒ ํ ๋น๋ task๊ฐ ๋์ด์ ํ์X
- parent๊ฐ ์กด์ฌํ๋๋ฐ OS๊ฐ parent๊ฐ ์ข ๋ฃ๋ ๋ child๊ฐ ๊ณ์๋๋ ๊ฑธ ํ์ฉํ์ง ์์ ๋
- child ํ๋ก์ธ์ค์ ๋์์ด ์ด์ํ ๋ (→ ์ด๊ฒ๋ ๋ถ๋ชจ๊ฐ ์์ ์ํ๋ฅผ ์ ์ ์์ด์ผ ํจ)
- ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์์ ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃ์ํค๋ 3๊ฐ์ง ๊ฒฝ์ฐ
- cascading termination (์ฐ์ ์ข
๋ฃ)
- parent๊ฐ ์ข ๋ฃ๋๋ฉด child๊ฐ ์กด์ฌํ ์ ์๊ฒ (→ ๋ช๋ช ์์คํ ์์๋ ๋ถ๋ชจ ์์ด ์์ ํ๋ก์ธ์ค๊ฐ ์คํ ๋ ์ ์์ด์ ์ข ๋ฃ)
- child๊ฐ ๋ค ์ข ๋ฃ๋์ด์ผ parent๊ฐ ์ข ๋ฃ๋ ์ ์๋๋ก. ์ฐจ๋ก๋๋ก ์๋ก ์ฌ๋ผ๊ฐ๋ฉด์ terminate.
- zombie & orphan process
wait()system call → ํ๋ก์ธ์ค ์ํ ์ ๋ณด์ ์ข ๋ฃ๋ ํ๋ก์ธ์ค์ pid๋ฅผ ๋ฐํ → ๋ถ๋ชจ ํ๋ก์ธ์ค๋ wait() system call์ ์ด์ฉํ์ฌ child ํ๋ก์ธ์ค์ ์ข ๋ฃ๋ฅผ ๊ธฐ๋ค๋ฆฐ๋ค.
pid = wait(&status);- ํ๋ก์ธ์ค๊ฐ ์ข ๋ฃํ๋ฉด ์ฌ์ฉํ๋ ์์์ OS๊ฐ ๋ค์ ๊ฐ์ ธ๊ฐ๋๋ฐ, ํ๋ก์ธ์ค์ ์ข ๋ฃ ์ํ๊ฐ ์ ์ฅ๋๋ ํ๋ก์ธ์ค ํ ์ด๋ธ์ ํด๋น ํญ๋ชฉ์ ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ wait()๋ฅผ ํธ์ถํ ๋๊น์ง ๋จ์์๊ฒ ๋๋ค.
- ์ฆ, ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ wait๋ฅผ ์ ํด์ฃผ๋ฉด zombie๊ฐ ๋๋ค.
- ํ๋ก์ธ์ค๋ ์ข ๋ฃ๋์์ง๋ง ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์์ง wait()๋ฅผ ํธ์ถํ์ง ์์ ํ๋ก์ธ์ค = ์ข๋น(zombie) → wait๋ฅผ ํ์ง ์์ผ๋ฉด ๋ฐํํ ๋ state๋ฅผ ๋ฐํํ ๊ณณ์ด ์๊ฒ ๋๋ค.
- parent ํ๋ก์ธ์ค๊ฐ wait()๋ฅผ ํธ์ถํ์ง ์์ ์ํ๋ก ์ข ๋ฃํด๋ฒ๋ฆฌ๋ฉด ๊ฐ ๊ณณ ์๋ ๋ถ๋ชจ๊ฐ ์๋ orphan process ๊ฐ ๋๋ค.
9๏ธโฃ Interprocess Communication (Models)
- ํ๋ก์ธ์ค ๊ฐ์ ์ปค๋ฎค๋์ผ์ด์ , cooperating → ๋ค๋ฅธ ํ๋ก์ธ์ค์ ์ํฅ์ ๋ฐ์ ์ ์๋ค.
- ํ๋ ฅํ ์ ์๋๋ก ๋ง๋ ์ด์ ?
- Information sharing : ๋ ๊ฐ์ ํ๋ก์ธ์ค๊ฐ ํ๋์ variable์ ๊ณต์

- Computation Speedup : ์ฌ๋ฌ ํ๋ก์ธ์ค → task๋ฅผ ๋ณ๋ ฌ์ ์ผ๋ก ์ฒ๋ฆฌ

- Modularity : ํ ์คํฌ๋ฅผ ๋ถ๋ฆฌ → ๊ด๋ฆฌ๊ฐ ์ฝ๋ค
- Convenience : ๋ถ๋ฆฌํด์ ๊ด๋ฆฌ → ํธ๋ฆฌํจ
- Information sharing : ๋ ๊ฐ์ ํ๋ก์ธ์ค๊ฐ ํ๋์ variable์ ๊ณต์
- ํ๋ก์ธ์ค ๊ฐ์ ํต์ (IPC) ๋ฐฉ์ ํฌ๊ฒ ๋ ๊ฐ์ง→ ๋ ๋ฐฉ์์ ์ฐจ์ด์ , ๋น๊ต! ๊ฐ ์ค์
- Shared memory : ์๋ ์์ ์ ํ๋ก์ธ์ค ๊ณต๊ฐ ์์ฒด๋ ๋ณดํธ๋ฐ์์ผํ๋๋ฐ, ๊ณต์ ํ๊ธฐ ์ํด์, ๋ค๋ฅธ ํ๋ก์ธ์ค๊ฐ ์ ๊ทผํ ์ ์๋๋ก
- Message Passing : ์ปค๋์ด ๋ฉ์ธ์ง ํ ๊ด๋ฆฌ
- ๋ณด๋ด๊ณ ์ถ์ ํ๋ก์ธ์ค๊ฐ ๋ฉ์์ง ํ์ ๋ฉ์ธ์ง๋ฅผ ์ง์ด ๋ฃ์ผ๋ฉด → ๋ฉ์ธ์ง๋ฅผ ์ฝ์ด์์ ์ถ๊ฐ์ ์ผ๋ก ๊ณต์ (์ปค๋ ์์ ๋ฉ์ผ ๋ฐ์ค๊ฐ ์กด์ฌํ๋ค. ํ๋ก์ธ์ค๊ฐ ํธ์ง๋ฅผ ๋จ๊ฒจ๋๊ณ , ๋ฐ๋ ์ ๊ฐ ์ฝ๋๋ค)
๐ IPC - Shared Memory
- ํ๋ก์ธ์ค ์ฌ์ด์ ๊ณต์ ๋๋ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ด ์กด์ฌ
- ์ปค๋(OS)์ด ์ง์ ๊ด์ฌ(control) X → User process ์ ์ ์ด(control)๋ก ํต์ ์ด๋ค์ง๋ค
- synchronize(๋๊ธฐํ) ๋ฌธ์
- p1๊ณผ p2๊ฐ ๋ชจ๋ shared memory ๊ณต๊ฐ์ ์ ๊ทผ ๊ฐ๋ฅ → p1์ด ์ด ๋ฐ์ดํฐ๋ฅผ p2๊ฐ ๋ฎ์ด๋ฒ๋ฆด ์ ์๋ค. : ํ๋ก์ธ์ค๊ฐ์ synchronization์ ํตํด ์๋์น ์๊ฒ ์์ ๋๊ฑฐ๋ ๋ฎ์ด์ง๋๊ฑธ ๋ฐฉ์งํด์ผํจ
๐ Example
- Producer(data ๋ง๋ฌ) ↔ Consumer(data ์ฌ์ฉํจ)
- ๋ ์ฌ์ด์ shared buffer ์กด์ฌ
- in, out์ผ๋ก circular buffer์ ์์๊ณผ ๋์ ํ์


๐ POSIX
- Shared Memory API

- ํ๋ก์ธ์ค๊ฐ shared memory segment ์์ฑ
shm_fd = shm_open(name, O_CREAT, O_RDWR, 0666);: ๊ณต๊ฐ ์ด๋ฆ, permission ๋ฑ์ ์ค์
- ์ค๋ธ์ ํธ์ ํฌ๊ธฐ ์ค์
ftruncate(shm_fd, 4096);: file descripter, byte ์ค์
- shared memory object์ ํ์ผ ํฌ์ธํฐ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋งตํ
char *buf = mmap();: mmap()์ ์ํด ๋ฐํ๋๋ ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํด์ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ์ ์ฝ๊ณ ์ธ ์ ์๋ค.
๐ IPC - Message Passing
- shared memory๋ ์๋ก ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ด๋์ ์ธ ์ค ์์์ง๋ง, ์ด๊ฑฐ๋ ๊ณต์ ๋ณ์์ ์์งํ์ง ์๋๋ค
- ์ง์ ์ ์ผ๋ก
send(message),receive(message) - ๋ฉ์ธ์ง ํฌ๊ธฐ๋ ๊ณ ์ ๋ ์๋ ์๊ณ , ๋ฐ๋ ์๋ ์๋ค!
- ์ปค๋์ด ๊ด๋ฆฌํด์ฃผ๋ communication link๊ฐ ์์ด์ผ ๋ฉ์ธ์ง๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์๋ค.
- ์๋ก ํฌํธ๊ฐ ์์ด์, ํฌํธ๋ฅผ ์ด์ด์ ์ด์ฉ๊ณ ์ ์ฉ๊ณ ํ๋ ๊ฒ์ฒ๋ผ ์ปค๋์์ ๋งํฌ๋ฅผ ์ด์ด์ ๋ฉ์ธ์ง๋ฅผ ์ฃผ๊ณ ๋ฐ๋๋ค.
- Physical(๋ฌผ๋ฆฌ์ ) ๊ตฌํ
- shared memory์๋ ๊ฐ๋ฅ์ธ๋ฐ ์ฐจ์ด๋ send, receive๋ก ๋ฉ์ธ์ง ๋จ์๋ก!!!
- Hardware bus, Network(Socket)
- Logical(๋
ผ๋ฆฌ์ ) ๊ตฌํ
- direct : ๋ณด๋ด๋ ์ฌ๋์ ์ง์ ํด๋๋๊ฒ →
send(Q, message);(message target์ ์ ๋ฌด ์ฐจ์ด) - indirect : ์ผ๋จ ๋ฐ์ค์ ๋ฉ์ธ์ง๋ฅผ ๋ฃ์ด๋๊ณ , ํ์ํ ์ฌ๋์ด ๊ฐ์ ธ๋ค ์ฐ๋ ๊ฒ →
send(message); - asynchronous : ๋ฉ์ธ์ง๋ฅผ ๋ณด๋ด๊ธฐ๋ง ํ๋ค. ๋ฐ์๋ค๋ ๊ฒ ํ์ธ ์ ํ๊ณ ๋ค๋ฅธ ์์ ์ํ
- synchronous : ๋๊ธฐ ๋ฐฉ์. ๋ด๊ฐ ๊ทธ ๋ฉ์ธ์ง๋ฅผ ๋ณด๋ธ ๊ฒ์ ๋ฐ์๋ค๋ ๊ฒ์ ํ์ธํด์ผ ํ๋ ๊ฒ.
- buffering : ๋ฉ์ธ์ง๋ฅผ ์ฌ๋ฌ๊ฐ ๋ณด๋ผ ๋, ๋ฒํผ์ ๋ฉ์ธ์ง๋ฅผ ๋ณด๊ดํ๊ฑฐ๋, …
- direct : ๋ณด๋ด๋ ์ฌ๋์ ์ง์ ํด๋๋๊ฒ →
'๐ฑ CS > ์ด์์ฒด์ (OS)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [์ด์์ฒด์ ๊ณต๋ฃก์ฑ ] Ch4. Threads & Concurrency (0) | 2024.05.12 |
|---|---|
| [์ด์์ฒด์ ๊ณต๋ฃก์ฑ ] Ch 2. Operating-System Structures (1) | 2024.04.26 |
| [์ด์์ฒด์ ๊ณต๋ฃก์ฑ ] Ch 1. Introduction (1) | 2024.04.13 |