Study/OS

[OS] Process Description and Control II

__PS 2024. 4. 19. 01:30
728x90

Mode Switch

현재 수행중인 프로세스를 교체하지 않고 수행중인 상태를 변화시키는 것

 

system call / exception -> 프로세스 관련 O

- kernel: process context에 위치

 

interrupt -> 프로세스 관련 X

- kernel: interrupt context에 위치

 

각각의 프로세스는 user, kernel stack이 존재

-> kernel은 user stack에 관계없이 실행 가능

 

When to Switch Process

1) Process switch

 

2) Interrupt

-> time slice에 의한 timer interrupt

-> blocked -> ready로 가는 경우 higher priority process인 경우 교체

 

3) Exception

-> 오류 발생 시, process switch

 

4) System call

-> user process를 blocked state로 변환


Process Switch

1) interrupt (time out): time slice를 모두 사용한 경우, block -> ready 중 높은 우선순위 

2) exception

3) system call: blocked state로 변환

 

1. save processor context -> PCB에 저장

2. ready / block queue에 접근

3. update, restore

 

Schedule Function

- ready process 사이에서 다음 수행할 프로세스를 선택

- 우선순위에 의해 결정


Process Creation

1. Directed

1) Allocate a new memory space: 공간 확보

2) load into new memory space: call stack 생성

3) PCB 생성 / 프로세스 실행

4) first process == super parent

 

2. Cloning

Fork: call once, return twice

- text, data, stack, PCB를 그대로 복사, 별도로 존재

- pid 존재, 0

순서는 scheduler에 의해 선정되며, 보장되지는 않음

 

모두 copy -> 비효율적

 

Copy on Write (COW)

write 할 때 변한 부분만 copy

ex) 코드 영역은 read-only

 

3. fork-exec

loading: call once, never return

load new code, data / pid는 바뀜

 

4. Exit

call once, never return

1) zombie state로 변환하고 PCB에 종료 상태 값을 저장

2) SIGCHLD 전송

3) reparenting / reaping


Zombie and Reaping

 

Zombie

PCB가 시스템에 남아있는 상태

 

Reaping

parent가 종료될 때, zombie 상태의 자식 process를 제거

-> parent가 wait 호출 || 종료


 

Potential Harm of the Zombie

메모리 누수

-> wait system call을 사용하여 reaping 대기

 

Orphan process

부모 process가 먼저 종료된 경우

1) 살아있는 자식: reparenting

2) 죽은 자식: reaping