Skip to content

Commit

Permalink
feat : [OS] Process (#31)
Browse files Browse the repository at this point in the history
* feat: [OS] process

* fix: add picture

* fix: picture

* fix: picture
  • Loading branch information
HwanGonJang authored Jan 13, 2025
1 parent 91a254f commit fa9d5da
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions OS/ํ”„๋กœ์„ธ์Šค.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
## ๊ฐœ์š”

Operating System(OS)์˜ ์ฃผ์š” ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ํ”„๋กœ์„ธ์Šค๋Š” ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ์˜ ์ถ”์ƒํ™”๋กœ, ์‹คํ–‰ ๋‹จ์œ„ ๋ฐ ๋ณดํ˜ธ ๋„๋ฉ”์ธ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์šด์˜์ฒด์ œ๋Š” ํ”„๋กœ์„ธ์Šค ์ƒ์„ฑ, ์‹คํ–‰, ์ƒํƒœ ์ „ํ™˜, ์ข…๋ฃŒ ๋“ฑ ํ”„๋กœ์„ธ์Šค์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.

---

## 1. ํ”„๋กœ๊ทธ๋žจ์—์„œ ํ”„๋กœ์„ธ์Šค๋กœ

### ํ”„๋กœ๊ทธ๋žจ ์ƒ์„ฑ ๊ณผ์ •

<img width="547" alt="Pasted image 20241126134119" src="https://github.com/user-attachments/assets/6fe807bd-c288-43b9-98df-64999d4c7e00" />


- **Source Code**: ์‚ฌ๋žŒ์ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ์ด๋‹ค.
- **Object File**: ์ปดํŒŒ์ผ๋Ÿฌ๋ฅผ ํ†ตํ•ด ๊ธฐ๊ณ„์–ด๋กœ ๋ณ€ํ™˜๋œ ํŒŒ์ผ๋กœ, CPU๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค.
- ํ”„๋กœ์„ธ์Šค๋กœ ๋ณ€ํ™˜๋˜๊ธฐ ์œ„ํ•œ ์ •๋ณด๊ฐ€ ์‚ฝ์ž…๋˜์–ด์•ผ ํ•œ๋‹ค.
- **Executable File**: ๋ง์ปค๋ฅผ ํ†ตํ•ด ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋œ ํŒŒ์ผ์ด๋‹ค.
- **Loader**: Executable File์„ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œํ•˜์—ฌ Address Space๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

---

### ์ปดํŒŒ์ผ๋Ÿฌ์™€ ๋ง์ปค

- **์ปดํŒŒ์ผ๋Ÿฌ**:
- Source Code๋ฅผ Object File๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.
- ํŒŒ์ผ์€ CPU ์•„ํ‚คํ…์ฒ˜(x86, ARM ๋“ฑ)์— ๋งž๊ฒŒ ์ƒ์„ฑ๋œ๋‹ค.
- **๋ง์ปค**:
- ์—ฌ๋Ÿฌ Object File๊ณผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ Executable File๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.
- ์‹ฌ๋ณผ๋“ค์˜ ์ฃผ์†Œ๋ฅผ ์ ˆ๋Œ€๊ฐ’(Absolute Address)์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

---

### ๋กœ๋”์™€ Runtime System

<img width="458" alt="Pasted image 20241126134647" src="https://github.com/user-attachments/assets/c3972d8f-ccfa-41db-af5a-ee502d3f189f" />


- **Loader**:
- Executable File์„ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œํ•˜๊ณ  Address Space๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
- ์ดˆ๊ธฐํ™”๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ๋ณต์‚ฌํ•˜๊ณ , ํ”„๋กœ๊ทธ๋žจ์˜ ์‹คํ–‰์„ ์ค€๋น„ํ•œ๋‹ค.
- **Runtime System**:
- ํ”„๋กœ๊ทธ๋žจ์˜ ํšจ์œจ์  ์‹คํ–‰์„ ์ง€์›ํ•˜๋ฉฐ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ดˆ๊ธฐํ™” ๋ฐ ๋ฉ”์ธ ํ•จ์ˆ˜ ํ˜ธ์ถœ์„ ๋‹ด๋‹นํ•œ๋‹ค.

---

## 2. ํ”„๋กœ์„ธ์Šค ๊ฐœ๋…

### ํ”„๋กœ์„ธ์Šค ์ •์˜

- **Execution Unit**: ํ”„๋กœ์„ธ์Šค๋Š” ์Šค์ผ€์ค„๋ง์˜ ๋‹จ์œ„์ด๋‹ค.
- **Protection Domain**: ํ”„๋กœ์„ธ์Šค ๊ฐ„์˜ ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ์„ ์ œํ•œํ•œ๋‹ค.
- **๊ตฌ์„ฑ ์š”์†Œ**:
- Program Counter
- Stack
- Data Section

### Process Image

ํ”„๋กœ์„ธ์Šค๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ƒ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„๋‹ค:

- **Text Segment**: ์‹คํ–‰ ๋ช…๋ น์–ด์™€ ๊ด€๋ จ๋œ ์ฝ”๋“œ.
- **Data Segment**: ์ดˆ๊ธฐํ™”๋œ ์ „์—ญ ๋ณ€์ˆ˜.
- **bss Segment**: ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์€ ์ „์—ญ ๋ณ€์ˆ˜.
- **Heap**: ๋™์ ์œผ๋กœ ํ• ๋‹น๋œ ๋ฉ”๋ชจ๋ฆฌ.
- **Stack**: ํ•จ์ˆ˜ ํ˜ธ์ถœ๊ณผ ๋กœ์ปฌ ๋ณ€์ˆ˜.

### Process State

ํ”„๋กœ์„ธ์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ƒํƒœ๋ฅผ ๊ฐ€์ง„๋‹ค:

- **New**: ์ƒ์„ฑ ์ค‘.
- **Running**: ์‹คํ–‰ ์ค‘.
- **Waiting**: ํŠน์ • ์ด๋ฒคํŠธ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ค‘.
- **Ready**: ํ”„๋กœ์„ธ์„œ ํ• ๋‹น ๋Œ€๊ธฐ ์ค‘.
- **Terminated**: ์‹คํ–‰ ์ข…๋ฃŒ.

---

## 3. ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ

### Process Control Block(PCB)

๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” OS์—์„œ PCB๋กœ ํ‘œํ˜„๋œ๋‹ค.

- **์ •๋ณด ํฌํ•จ**:
- Process State
- Program Counter
- CPU Registers
- Memory Management Information
- I/O Status Information

### Context Switch

Context Switch๋Š” CPU๊ฐ€ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๊ธฐ์กด ํ”„๋กœ์„ธ์Šค์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๊ณ  ์ƒˆ๋กœ์šด ํ”„๋กœ์„ธ์Šค์˜ ์ƒํƒœ๋ฅผ ๋กœ๋“œํ•˜๋Š” ์ž‘์—…์ด๋‹ค.

- **ํŠน์ง•**:
- Context Switching์€ Overhead๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.
- ํ•˜๋“œ์›จ์–ด ์ง€์›์— ๋”ฐ๋ผ ํšจ์œจ์„ฑ์ด ๋‹ฌ๋ผ์ง„๋‹ค.
- **CISC vs RISC**:
- CISC
- ๋ณต์žกํ•œ ๋ช…๋ น์–ด ์…‹ -> ๋†’์€ ํšจ์œจ, ํด๋Ÿญ ์†๋„ ์ €ํ•˜
- ๋ณต์žกํ•œ ํšŒ๋กœ
- RISC
- ๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด ์…‹ -> ๋†’์€ ํด๋Ÿญ ์†๋„, ๋น ๋ฅธ ์ˆ˜ํ–‰ ์†๋„
- ์ ˆ์•ฝ๋œ ๊ณต๊ฐ„์— ๋” ๋งŽ์€ ๋ ˆ์ง€์Šคํ„ฐ ์žฅ์ฐฉ
- RISC๋Š” ๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น ๋ฅธ ์ˆ˜ํ–‰ ์†๋„๋ฅผ ์ œ๊ณตํ•˜์ง€๋งŒ, Context Switching์—์„œ ๋” ๋งŽ์€ Overhead๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

### Process Creation

ํ”„๋กœ์„ธ์Šค๋Š” Concurrentํ•˜๊ฒŒ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋™์ ์œผ๋กœ ์ƒ์„ฑ ๋ฐ ์ข…๋ฃŒ๋œ๋‹ค.

<img width="207" alt="Pasted image 20241126141508" src="https://github.com/user-attachments/assets/5548d601-85d7-46c9-80c0-62ccf9fbe0fc" />


- **Unix ์‹œ์Šคํ…œ**:
- `fork()` ์‹œ์Šคํ…œ ์ฝœ๋กœ Parent Process๋กœ๋ถ€ํ„ฐ Child Process๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
- Parent์™€ Child๋Š” ๋ฉ”๋ชจ๋ฆฌ์™€ ์ž์›์„ ๊ณต์œ ํ•˜๊ฑฐ๋‚˜ ๋…๋ฆฝ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

### Process Termination

ํ”„๋กœ์„ธ์Šค๋Š” ์‹คํ–‰์ด ๋๋‚œ ํ›„ ์ข…๋ฃŒ๋œ๋‹ค.

- **์ข…๋ฃŒ ์กฐ๊ฑด**:
- ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋งˆ์ง€๋ง‰ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ ํ›„ OS์— `exit()` ์‹œ์Šคํ…œ ์ฝœ์„ ํ†ตํ•ด ์ข…๋ฃŒ๋ฅผ ์š”์ฒญํ•œ๋‹ค.
- **๋™์ž‘ ๊ณผ์ •**:
- ์ž์‹ ํ”„๋กœ์„ธ์Šค์˜ ์ถœ๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ Parent Process๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค(์˜ˆ: `wait()` ํ•จ์ˆ˜ ์‚ฌ์šฉ).
- OS๋Š” ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‚ฌ์šฉํ•˜๋˜ ์ž์›์„ ํšŒ์ˆ˜ํ•˜๊ณ  ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ•ด์ œํ•œ๋‹ค.
- **๋น„์ •์ƒ ์ข…๋ฃŒ**:
- ํ”„๋กœ์„ธ์Šค๋Š” `abort()` ํ•จ์ˆ˜๋‚˜ `SIGABRT` ์‹ ํ˜ธ๋ฅผ ํ†ตํ•ด ๋น„์ •์ƒ์ ์œผ๋กœ ์ข…๋ฃŒ๋  ์ˆ˜ ์žˆ๋‹ค.
- ์ด ๊ฒฝ์šฐ Core Dump๊ฐ€ ์ƒ์„ฑ๋˜์–ด ๋””๋ฒ„๊น…์— ์‚ฌ์šฉ๋œ๋‹ค.

---

## 4. ํ”„๋กœ์„ธ์Šค ํ˜‘๋ ฅ

<img width="219" alt="Pasted image 20241126141945" src="https://github.com/user-attachments/assets/b3d0c5be-8d37-429a-b413-ecc076574a37" />


ํ”„๋กœ์„ธ์Šค ํ˜‘๋ ฅ์€ ์„œ๋กœ ๋…๋ฆฝ์ ์ธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ƒํ˜ธ์ž‘์šฉํ•˜์—ฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

- **์žฅ์ **:
- ์ •๋ณด ๊ณต์œ .
- ๊ณ„์‚ฐ ์†๋„ ํ–ฅ์ƒ.
- ๋ชจ๋“ˆํ™” ๋ฐ ํŽธ์˜์„ฑ ์ œ๊ณต.

---

## ๊ฒฐ๋ก 

ํ”„๋กœ์„ธ์Šค๋Š” OS์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ด€๋ฆฌ ๋‹จ์œ„๋กœ, ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋‹ค์–‘ํ•œ ์ •๋ณด์™€ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ํฌํ•จํ•œ๋‹ค. ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ์˜ ์ดํ•ด๋Š” ํšจ์œจ์ ์ธ ์šด์˜์ฒด์ œ ์„ค๊ณ„์™€ ์„ฑ๋Šฅ ์ตœ์ ํ™”์˜ ํ•ต์‹ฌ์ด๋‹ค. Context Switching, Process State, PCB ๋“ฑ์˜ ๊ฐœ๋…์€ ์‹œ์Šคํ…œ ์ž์›์˜ ํšจ์œจ์  ํ™œ์šฉ๊ณผ ์•ˆ์ •์„ฑ ๋ณด์žฅ์„ ์œ„ํ•œ ๊ธฐ์ดˆ๊ฐ€ ๋œ๋‹ค.

0 comments on commit fa9d5da

Please sign in to comment.