Professional Documents
Culture Documents
Chapter03 2
Chapter03 2
1
Process Image
2
Process Control Block (PCB)
Table 3.5
Process Identification
Processor State Information
Process Control Information
3
PCB
Process identification
– Identifiers
• Numeric identifiers that may be stored with the process
control block include
– Identifier of this process
– Identifier of the process that created this process (parent process)
– User identifier
4
PCB
5
PCB
6
PCB
7
PCB
8
PCB
9
PCB
10
PCB
11
User processes in VM
12
3.4 Process Control
Modes of Execution
– User mode
• Less-privileged mode
• User programs typically execute in this mode
– System mode, control mode, or kernel mode
• More-privileged mode
• Kernel of the operating system
13
Modes of Execution
14
Modes of Execution
Reason for using Two modes
– To protect OS and OS tables
15
잠깐 이해하고 가기
이해해 보자: System Call
16
잠깐 이해하고 가기
System Calls
Application programs talk to OS via system calls
The programmer’s functional interface to the
LINUX kernel
잠깐 이해하고 가기
System Calls
Application code
User
fget() Standard Library Function
fscanf() Library Buffer
System calls
– Well defined entry points directly into the kernel
– Look like C functions which can be called from a
user’s program
• Just need to include the appropriate header
Ex) read(), write()
Library functions
– The library function is often more elaborate than
the system call, and usually invokes the system
call
Ex) fprintf() fscanf()
잠깐 이해하고 가기
User mode vs. Kernel mode
앞으로 살펴 볼 것들…
Process creation
Process switching
– 언제 process switching이 발생하는가?
– Process switch가 발생할 때, OS가 할 일은?
– Process switch와 Mode switch의 차이는?
21
PCB
22
PCB
23
Control to OS…
Possible events that may give control to the OS
– Interrupt
– Trap
– Supervisor call
24
Process Switching
Interrupt
– External to the execution of the current instruction
– 종류:
(1) Clock interrupt
• process has executed for the maximum allowable time slice
(2) I/O interrupt
• When I/O action has occurred
(3) Memory fault
• memory address is in virtual memory so it must be brought
into main memory
25
Process Switching
Trap
– Associated with the execution of the current
instruction
– error or exception occurred
– may cause process to be moved to Exit state
26
Clock interrupt가 발생하면…
Processor에 대한 control OS
– OS는 현재 running process A를 ready 상태로 바꾸고
– Ready process 중 하나를 선택하여 (process B) running
상태로 바꾼 후…
– Processor 에 대한 control을 Process B에게 양도…
즉, process switching 발생
자세히 살펴보면…
27
Process Switching Step
1. Save context of processor including program counter
and other registers
2. Update the process control block of the process that is
currently in the Running state
– Running Ready or Blocked or Ready/Suspend
3. Move process control block to appropriate queue –
ready; blocked; ready/suspend
4. Select another process for execution
5. Update the process control block of the process
selected (Ready Running)
6. Update memory-management data structures
7. Restore context of the selected process
28
그런데…
Interrupt가 발생하면 항상 process switching이 발생해
야 하나?
– 즉, interrupt 발생하면
– 현재 running process의 state를 block/ready로 바꿔야 하나?
29
Reading…
Mode Switching
…
If an interrupt is pending, the processor does the following :
여기서..잠깐…
CHAP 1을 다시 돌아보면…
31
또는…
System call 호출 시에도…
– User process에서 함수 호출 시…
– 잠깐 OS가 control을 갖게 되는데…
– 이 경우에도 현재 user process의 state를 변환? 또는 그대로?
Process
Process
A
A
Process
B Interrupt occurs
33
Process switch vs. Mode switch
Process switch
Mode switch
Process
Process
A OS
A
Process
B
34
Process switch vs. Mode switch
Process switch
Mode switch
Process
Process
A OS
B
A
Process
B
35
Mode Switching (1)
When interrupt issues, the processor does…
– Set the program counter to the starting address of an
interrupt handler program
– What happens next?
• Process switching?
Mode switch
– may occur without changing the state of the process that is
currently in the Running state..
– 현재 RUNNUNG 상태의 프로세스를 그대로 RUNNING 상태
로 두고…
36
Mode Switching (2)
First instruction of the interrupt handler code…
– Context of the process that has been interrupted is saved
into that PCB of the interrupted program
– 다시 말하면…Processor state information is saved to be
able to resume the program that was interrupted
After interrupt has executed…
– Currently running process will resume execution
– All information are restored when control is returned to the
program…
Process
Process
A
A
Process
B Interrupt occurs
38
Process switch vs. Mode switch
Process switch
Mode switch
Process
Process
A
A
39
Process switch vs. Mode switch
반드시 process switch가 발생하는 event는?
– 현재 running Process가 더 진행하지 못하는 경우…
• Clock interrupt,
• Memory Fault
• Trap (치명적 오류로 인해 process가 더 진행 못하는 경우)
• System call (I/O관련 호출처럼 바로 service가 종료되지 못하는
경우는 process switch 발생)
어떤 것이 cost가 더 드는 operation?
– Process switch
– Mode switch
40
3.5 Execution of the Operating System
그렇다면 OS는 무엇인가?
– 같은 개념의 Process? 또는 예외적인 무엇?
OS를 보는 3가지 관점
– Non-process Kernel (프로세스 절대 아님)
– Execution within User process
– Process-based Operating System (일반 프로세스)
41
OS 관점
Non-process Kernel
– Execute kernel outside of any process
– Operating system code is executed as a separate entity that
operates in privileged mode
– Running process is interrupted or issues a supervisor call, the
mode context of this process is saved and control is passed to
the kernel
– Older OS model
– Concept of process is considered to apply only to user program
42
OS 관점
43
dispatcher
44
OS codes & data
46