# 1. Operating System
What does a Mordern OS do?
Provide abstractions Provide Standard Interface Mediates Resource Usage Consumes Resources
# 2. Processes and Threads
# 2.1 What is process and threads
Process is an execution stream in the context of a particular process state. Thread is an execution stream in the context of a thread state.
The key difference: Multiple threads share parts of their state.
Allowing read write the same memory, but each thread still have own registers.
- The threads must corrdinate their activities very closely.
- It is much easier to coordinate activities.
# 2.2 Process state information
- Open file tables
- Singal management information
# 2.3 Multiprogramming
Multiple processes at a time. Allow system to separate out activites cleanly.
# 2.4 Context switch
Because multiprogamming, there needs to share the resource, such as CPU.
Therefore, OS needs the ability to switch from one process to another. That is Context Switch
# 2.5 PCB
The way to implement the Context Switch is to save and restore the hardware state in PCB (Process Control Block).
# 2.5.1 PCB depends on hardward
Porcessor Status Word
Some machine needs the Memory Management Unit(MMU)
But the older PC switch all the process's memory out to disk
# 2.6 Event-driven
OS is fundamentally event-driven.
That is to wait for an event to happen, response appropriately to the event, then wait for the next event
# 2.7 Thread Control Block
It is tipically register.
Don't need to do anything to the MMU when switch threads.
# 2.8 Each user process is backed by kernel thread
That is the OS will have a separate thread for each process. And perform the OS activities on behalf of the process.
Allow the programmer to program the actions associate with that activity as a single serial stream of actions and events
Programmer does not have to deal with the complexity of interleaving multiple activities on the same thread