CS/운영체제

2. Process

HWAN JJ 2022. 3. 4. 21:32

Summary

- 프로세스는 무엇인가? 어떻게 생성되는가? (5단계)

- 어떻게 프로그램들에게 각자마다 CPU가 하나씩 있다는 환상을 줄 것인가?

  • By virtual CPU & Time sharing ⇒ context switch (overhead 존재..)
  • CPU를 가상화하고, 프로그램마다 CPU를 차지하는 시간을 배정해서 실현할 수 있다.
  • CPU를 차지하는 프로그램이 바뀔 때마다 내부 레지스터의 값 등 프로그램의 다음번 실행을 위해서 계속 저장해야하는 값을 다른 공간에 저장하고, 불러오는 Context Switch 라는 과정이 존재하고, 이는 필연적으로 Overhead가 존재한다.

- Process API 에는 어떤 종류의 명령들이 있는가

- Process States (Reay, Running, Blocked) 각각 구분 가능?

- Process control block은 무엇인가?


What is process?

  • Process is a running program
    => 프로세스는 실행중에 있는 프로그램을 의미한다.
  • Process 는 Memory, Register으로 이루어져 있다.
  • 이 프로세스의 메모리와 레지스터를 따라 Instruction을 수행하여, 프로그램을 실행한다.


Process API

현대 OS에서는 아래 API들이 존재한다.

  • Create : create a new process (새로운 프로세스 생성)
  • Destroy : halt a runaway process (프로세스 종료)
  • Wait : wait for a process to stop running (프로세스 종료까지 현재 프로세스 대기)
  • Miscellaneous Control : Some kind of method to suspend a process then resume it
    (프로세스를 중지시켰다가 다시 실행)
  • Status : Get some status info about a process (프로세스의 정보 반환)


Process Creation

  • 프로세스 생성과정
  1. Load a program code into memory, into the address space of the process
    • 프로그램은 처음에는 Disk에 executable format으로 존재한다.
    • 요즘 OS 들은 이 과정을 **"lazily"**하게 실행한다.
    • 과거에는 프로그램들의 크기가 작아서 메모리에 다 올려서 써도 좋았지만,
    • 현대에는 프로그램들의 크기가 커지면서 그때 그때 필요한 부분들만 올려서 실행
  2. Program's run-time stack is allocated
    • Use stack for local variables, function parameters, and return address
    • Initialize stack with arguments ⇒ argc & argv array of main()
  3. Program's heap is created
    • Used for requested dynamically allocated data
    • malloc() & free()
  4. OS does some initialization tasks
    • input/output (I/O) setup
  5. Start the program running at the entry point, namely main()
    • OS transfers control of CPU to newly-created process

Process States

  1. Ready
    • process is ready to run but for some reason the CPU has chosen not to run it at this given moment
    • 곧 실행될 예정, 아직 CPU 할당 받지 못 함
  2. Running
    • process is running on a processor
    • 지금 이 시간 돌아가고 있는 경우
  3. Blocked
    • process has performed some kind of operation (이미 실행됨)
    • When a process initiates an I/O request to a disk(오래 걸리는 작업), it becomes blocked and thus some other process can use the processor
  4. I/O request 가 없는 경우,
    • 돌던 프로세스를 끝내고 다음 프로세스가 Ready 되어 있으면 프로세스를 실행
  5. I/O request 가 있는 경우,
    • 돌던 프로세스를 Block하고, 다음 프로세스가 Ready 되어 있으면 프로세스를 실행, 그 후 원래 프로세스의 I/O가 끝났으면 실행하고 종료

PCB (Process Control Block)

  • 프로세스의 정보를 담고 있는 구조체, 각 프로세스에 하나씩 존재
  • Register context 역시 존재한다.

 

 

How to provide the illusion of many CPUs? 

어떻게 Process에게 CPU를 독점하는 것처럼 사용할 수 있도록 해주나?

  • CPU virtualizing 을 통해서
  • OS는 virtual CPU가 여러개 존재하는거 같은 환상을 제공해줄 수 있다.
  • How?
    • By Time Sharing
    • 하나의 프로세스를 돌리다가 정지하고 다른 프로세스를 실행
    • (context switch) overhead 존재..
    • 위 과정을 context switch 라고 하는데 자주 바꿀수록 overhead 증가

 

 


PS. 혹시 보고 의문점이나 질문이 있으시면 댓글 달아주시면 제가 아는 선에서 대답을 드리겠습니다