* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Operating Systems Concept
?What is an operating system?
?Operating system architecture
?Process concept
?CPU scheduling
?Memory management
?File and I/O systems
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Concept
?Process
?An active entity
?The corresponding passive entity
?Program code
new
ready
running waiting
zombie
fork
scheduled
interrupt exit
I/O or event waiting completed
stop
suspend resume
* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 89-97, p 126.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Concept
?Process Image in Memory
?System Resources
? Program Counter (PC)
? Process Status Register
? Stack Pointers (sp)
? Memory
? etc.
Code Segment Data Segment
PC heap
user stack argv, argc,…
sp
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Concept
?Process Control Block Struct PCB {
char p_pid;
char p_pri;
char p_ppid;
int pc; /* program counter */
…
int rq_former, rq_next; /* for ready queue*/
int files[NFILE];
} PCB[NPROC];
• major queues:
• I/O queues
• ready queue
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Concept
Process i OS Process j
Save state into PCB[i]
..
Load state from PCB[j]
Save state into PCB[i]
Load state from PCB[j]
.. .. ..
Interrupt or system call
Interrupt or system call
dispatch
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Scheduling
?A Ready Queue
…
Priority -decreasing
0 1 2
PCBi PCBj
PCBk
• Select the highest-priority process to run and de-queue it!
• Hook the running process
back to the ready queue!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Context Switching – Necessary Overheads for Multiprogramming
?Def.
?Switch the CPU from one process to another process
?Save the state (or called context) of the running process
?Reload the state of the ready process
?Context Switching Time
?Hardware-dependent!
?Multiple register sets!
?Special hardware instructions!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Process Concept
?Kernel-Supported Thread
?A program counter
?A register set
?A stack space
?User-Level Thread
Code Segment Data Segment
user stack sp1
PC1 user stack sp2
PC2
* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 103
OS
A process with one
kernel-supported thread
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.