아주대학교 김상훈 교수님의 운영체제 강의와 강의 자료를 바탕으로 작성된 글입니다.
What is Process Scheduling?
-
Runnig multiple processes on multiple processors

-
What if we have only one processors?
-> OS creates an illusion that each process has its own CPU and memory
-> 즉, A가 돌다가 timer interrupt 터지면 timer handler로 jump함. handler code 실행하다 보면 scheduler 코드로 와서 다른 process 돌릴 수 있게 됨

Process Scheduling
- Goal: Quickly switch processes onto CPU
- 실행 중인 process가 I/O를 기다릴 때 CPU는 idle한 상태가 됨
- CPU의 idle 상태를 방지하고자 여러 process를 바꾸며 실행시키는 게 process scheduling임
- Process scheduler selects a process among available processes for next execution on CPU
- Learning process scheduling means to learn;
- How to switch between processes
- How to find/manage available processes for scheduling
- ready process를 어떻게 찾을까
- 어떤 process를 복원할지
- 복원할 process는 어디서부터 실행해야 하는지
- How to select next process to run
- ready 상태의 process 중 어떤 process를 뽑는 게 최선일까?
Parallelism vs Concurrency
CPU가 2개 있어서 여러 process가 동시에 실행되는 경우가 있을 것이고, CPU 1개에서 여러 process가 번갈아 실행되는 경우가 있을 것이다. 거시적으로 봤을 때는 여러 process가 동시에 실행되는 것처럼 보이지만, 이걸 좀 더 세부적으로 구별할 필요가 있다.
- Parallelism
- Imply a system that can perform more than one task simultaneously
- 여러 명이 각자의 삽을 들고 각자의 구덩이를 파는 것

- Concurrency
- Support more than one task making progress
- 여러 명이 한 개의 삽을 돌아가며 쓰면서 각자의 구덩이를 파는 것
- Concurrency는 parallelism 없이 제공이 가능하다.

Time Sharing in Modern OSes

Mechanism vs. Policy
-
Mechanism
- How to do something?
- It refers to the process, methods, or tools used to achieve a particular task
-
Policy
- What should be done?
- What is the next process to run?
- system은 중요 작업을 비중요 작업보다 우선해야 한다.
- It defines the rules, objectives, or guidelines that describe what actions or outcomes are desired.
Policy는 바뀔 수 있지만 Mechanism은 좀 general하게 되어 있다. 따라서 잘 만들어진 Mechanism은 policy가 바뀌어도 잘 바뀌지 않는다.
Context Switch
-
When CPU switches to another process, the system must save the state of the current process and load the state of the next process
-
Context of a process is represented in the PCB
- PCB: Process Control Block
- Each PCB represents a process
-
Context-switch time is overhead
- The system does no useful work while switching

1. P0가 실행되다가 context out 되어 PCB0에 저장된다.
2. PCB1로부터 P1의 상태를 복원한다. P1은 context in 된다.
Scheduling Queues
