3 프로세스 관리

2024. 1. 19. 20:22프로그래밍 공부/OS

Job vs Process

작업(Job) / 프로그램(Program)

실행할 프로그램 + 데이터

컴퓨터 시스템에 실행 요청 전의 상태

 

프로세스(Process)

실행을 위해 시스템(커널에)등록된 작업

시스템 성능 향상을 위해 커널에 의해 관리됨

 

Program                                            Kernel

Data      Submission Registration    Process    Computer System

Job

 

Job vs Process

프로세스   메모리

               프로세스

디스크

프로그램

 

프로세스의 정의

실행중인 프로그램

커널에 등록되고 커널의 관리하에 있는 작업

각종 자원들을 요청하고 할당 받을 수 있는 개체

프로세스 관리 블록(PCB)을 할당 받은 개체

능동적인 개체(active entity)

실행 중에 각종 자원을 요구, 할당, 반납하며 진행

 

Process Control Block (PCB)

커널 공간 (kernel space) 내에 존재

각 프로세스들에 대한 정보를 관리

 

프로세스의 종류

표 3-1 프로세스의 종류

구분 종류 설명
역할 시스템(커널) 프로세스  
  사용자 프로세스  
병행 수행 방법 독립 프로세스  
  협력 프로세스  

 

자원(Resource)의 개념

커널의 관리 하에 프로세스에게 할당/반납되는 수동적 개체(passive entity)

 

자원의 분류

H/W resources

Processor, memory, disk, monitor, keyboard, Etc.

S/W resources

Message, signal, files, installed SWs, Etcs.

 

Process Control Block (PCB)

OS가 프로세스 관리에 필요한 정보 저장

프로세스 생성 시, 생성됨

Kernel 각 프로세스들에 대한 상태정보 저장

Memory

 

PCB가 관리하는 정보

PID: Process Identification Number 프로세스 고유 식별 번호

스케줄링 정보: 프로세스 우선 순위 등과 같은 스케줄링 관련 정보들

프로세스 상태: 자원 할당, 요청 정보 등

메모리 관리 정보: Page table, segment table 등

입출력 상태 정보: 할당 받은 입출력 장치, 파일 등에 대한 정보 등

문맥 저장 영역 (context save area): 프로세스의 레지스터 상태를 저장하는 공간 등

계정 정보: 자원 사용 시간 등을 관리

 

PCB 정보는 OS 별로 서로 다름

PCB 참조 및 갱신 속도는 OS의 성능을 결정 짓는 중요한 요소 중 하나

 

프로세스의 상태 (Process States)

프로세스 - 자원 간의 상호작용에 의해 결정

프로세스 상태 및 특성

상태 자원 할당 상태
Active(swapped-in) Running 프로세서 O 메모리 O
Ready 프로세서 X, 기타 자원 O
Bloked, asleep 프로세서 X, 기타 자원 X
Suspended(swapped-out) Suspended ready 프로세서 X 메모리 X
Suspended block 프로세서 X, 기타 자원 X

 

Process State Transition Diagram

Created State

작업(Job)을 커널에 등록

PCB 할당 및 프로세스 생성

커널

가용 메모리 공간 체크 및 프로세스 상태 전이

Ready or Suspended ready

 

Job -(Submit)→ Created -Memory allocated→ ready

                                             Waiting memory allocation→ suspended ready

 

Ready State

프로세서 외에 다른 모든 자원에 할당을 받은 상태

프로세서 할당 대기 상태

즉시 실행 가능 상태

 

Dispatch (or Schedule)

Ready state → running state

 

Processor vs Process

CPU

 

ready -dispatch (schedule)→ running

              Processor allocated

 

Running State

프로세서와 필요한 자원을 모두 할당 받은 상태

 

Preemption

Running state → ready states

프로세서 스케줄링 (e.g, time-out, priority changes)

Block/sleep

Running state -> asleep state

I/O 등 자원 할당 요청

 

running -Timer run-out (preemption) → ready

              -sleep (block)→ asleep

 

Blocked/Asleep State

프로세서 외에 다른 자원을 기다리는 상태

Wake-up

Asleep state → ready state

 

                     running

  dispatch

 (scheule)

        ↗                        ↘

ready    ←wake up- asleep

 

Suspended State

메모리를 할당 받지 못한(빼앗긴) 상태

Memory image를 swap device에 보관

Swap device: 프로그램 정보 저장을 위한 특별한 파일 시스템

커널 또는 사용자에 의해 발생

Swap-out(suspended), Swap-in(resume)

 

                  ready                               asleep

                    | ↑ swap-in(resume)      | ↑ swap-in(resume) (active)

  swap-out↓ |                     swap-out↓ |                           (suspended)

(suspend)                           (suspend)

            suspended                        suspended

                ready        ←wake up -      blocked

 

Terminated/Zombie State

프로세스 수행이 끝난 상태

모든 자원 반납 후,

커널 내에 일부 PCB 정보만 남아 있는 상태

이후 프로세스 관리를 위해 정보 수집

running -exit→ terminated

 

프로세스 관리를 위한 자료구조

Ready Queue

I/O Queue

Device Queue

 

Ready list: 스케줄러에 의해 선택됨

Blocked list: 자원에 따라 각각 관리

 

인터럽트(Interrupt)

예상치 못한, 외부에서 발생한 이벤트

Unexpected, external events

 

인터럽트의 종류

I/O interrupt

Clock interrupt

Console interrupt

Program check interrupt

Machine check interrupt

Inter-process interrupt

System call interrupt

 

인터럽트 처리 과정

Interrupt → 인터럽트 발생

                            ↓

커널 개입 → 프로세스 중단

                            

                  인터럽트 처리(interrupt handling) → 인터럽트 발생 장소, 원인 파악

                                                                                                 ↓                       Interrupt handling

                                                                             인터럽트 서비스 할 것인지 결정

                                                                                                 ↓

                                                                             인터럽트 서비스 루틴                       Interrupt service

                                                                             (interrupt service routine) 호출 

 

인터럽트 처리 과정

Processor           Interrupt handling Interrupt handler Kernel

Pi    Context saving PCBi PCBj           

 

Interrupt                                         Memory

 

Processor Pi    Kernel Scheduler    Pj

                        Interrupt

 

Context Switching (문맥 교환)

Context

프로세스와 관련된 정보들의 집합

CPU register context => in CPU

Code & data, Stack, PCB => in memory

 

Context saving

현재 프로세스의 Register context를 저장하는 작업

 

Context restoring

Register context를 프로세스로 복구하는 작업

 

Context switching Process switching

실행 중인 프로세스의 context를 저장하고,

앞으로 실행할 프로세스의 context를 복구하는 일

커널의 개입으로 이루어짐

 

Context Switch Overhead

Context switching에 소요되는 비용

OS마다 다름

OS의 성능에 큰 영향을 줌

 

불필요한 Context switching을 줄이는 것이 중요

예, 스레드 사용 등

 

요약

프로세스의 개념

프로세스 상태 변화

PCB(프로세스 관리 블록)

인터럽트

Context Switch

'프로그래밍 공부 > OS' 카테고리의 다른 글

6 프로세스 동기화 & 상호배제  (0) 2024.01.24
5 프로세스 스케줄링  (0) 2024.01.22
4 스레드 관리  (0) 2024.01.21
2 운영체제 개요  (0) 2024.01.19
1 컴퓨터 시스템 개요  (0) 2024.01.19