---
title: "Operating System - Chapter 1: Introduction to Operating System"
---
# <u>Operating System Chapter 01</u><br><span>Introduction to Operating System</span>
###### tags — `operating-system`, `note`
<style>
.markdown-body h1 > span:last-child{
font-size: 18pt;
float: right;
width: 100%;
text-align: right;
border-bottom: 1pt #EEE solid;
padding-bottom: 5pt;
margin-bottom: 5pt
}
.markdown-body h1{
border: none;
}
.markdown-body i, em{
font-weight: 550;
color: sienna;
}
.markdown-body h3::before{
content: "▮ ";
position: relative;
left: -3px;
bottom: 2px
}
.markdown-body h2{
padding-top: 5px;
padding-left: 6px;
background: linear-gradient(90deg, rgba(0,0,0,0.15) 0%, rgba(58,121,9,0.15) 25%, rgba(255,255,255,0) 100%);
}
.markdown-body img{
width: 100%;
border: 3px #888888 solid
}
li li strong{
font-weight: 600;
}
.word-meaning{
color: #CCCCCC;
}
</style>
## Component of a Operating System
+ **Kernel** — The program that is *always* running on the computer.
+ **Middleware** — Frameworks that ease application development and provide feature.
+ **System Software** — Aids the kernel.
## Component of a General-Purpose Computer
+ **CPU** — One or more, the **c**entral **p**rocessing **u**nit.
+ **Device Controller** — Controls a type of devices.
+ **Device Driver** — Provide the operating system a uniform interface to the device controller.
+ **Shared Memory**
+ **Memory Controller** — Rules access to the shared memory.
+ **Bus** — Connects the above components.

## Interrupts
When a hardware triggers an interrupt, the CPU backups its current execution and executes the *interrupt service routine*. Since they occur frequently, the routine must be performed fast.
The **Interrupt Vector**, contains a table of addresses pointing to the various interrupt service routines .
### Implementation of Interrupts
+ **Inturrupt-Request Line** — Connects to the CPU hardware, which the CPU checks after every instructions. Signals interruption and the corresponing routine table index.
+ **Interrupt-Handler Routine** — The routine where the specified routine index would jump to.
The handler backups any states that would be changed. After the routine, it executes a `return_from_interruption` instruction to restore the states. Using keywords,
+ The device controller *raises* a interruption,
+ The CPU *catches* the interruption and,
+ *Dispatches* to the corresponding handler,
+ Finally, the handler *clears* the interrupt.
### Interrupt-Controller Hardware
Handles the following work, apart from basic interrupt handling:
+ Defer interrupt handling during critical processing
+ Efficent way to dispatch to the proper handler
+ Distinguish interrupts with different priorities and respond.
### Interrupt-Request Lines
+ **Nonmaskable Interrupt** — Reserved for events, like errors.
+ **Maskable Interrupt** — Used by device controllers to request service, can be blocked by CPU during critical sequences.
### Interrupt Chaining
The entries of the interrupt vector points to *a list of handlers*, and checks one by one which could do the work. Balances between a huge interruption table and the time-consuming search by only 1 interrupt handler.
## Storage
+ **RAM** (Random Access Memory)
- *main memory* — most of programs stores here.
- *Volitale* — Data lost when power off.
- Implemented on **DRAM**(Dynamic random-access memory).
+ **Firmwares**
- E.g., **EEPROM**(Electrically Erasable Programmable Rean-Only Memory)
- Used to store the *bootstrap program* — Loads the operating system.
- *Non-volitale* — Data still present after power loss.
- Slow on writing data, cannot rewrite frequently.
All storage form provide *array of bytes*, with addresses assigned to all of it.
### Instruction-Execution Cycle — Under <u>von Neumann Architecture</u>
1. Instruction fetchd from memory, stored to *instruction register*.
2. Instruction *decoded* and fetch operand data.
3. Execution.
4. Writeback result to memory (if need to).
### Secondary Storage
+ **HDD** (Hard Drive Disk)
+ **NVM** (Nonvolatile Memory)
Used to deal with the two cons of main memory:
1. Too small to store all needed program and data.
2. Volitile, cannot store permanently
### Tertiary Storage
+ Slow and large for special purposes.
+ E.g., CD-ROM, cache memory

## I/O Structure
Interrupt driven I/O creates huge overhead on bulk data transfer, so the devices utilies **DMA** (Direct Memory Access) — Directly write data onto the storage, not envolving the CPU. Only 1 interrupt is generated after each block of data is finished transferring, signaling the CPU.
## Components of Computer System
+ **CPU** — The hardware that executes instructions.
+ **Processer** — Processor—Aphysical chip that contains one or more CPUs.
+ **Core** — The basic computation unit of the CPU.
+ **Multicore** — Including multiple computing cores on the same CPU.
+ **Multiprocessor** — Including multiple processors.
### SMP — Symmetric Multiprocessing
Each peer CPU has its own registers, own cache, can execute all instruictions.
Shared cache also exists between CPUs.
### NUMA — Non-Uniform Memory Access
Each CPU owns its seperate local memory, but all shares a physical address space, connected by *shared system interconnect*. Memory access on own memory is faster than accesing others', thus "non-uniform".
### Blade Servers
System with <u>mutiple processer boards, I/O boards, networking boards, etc.</u>, but each holds its own operating system and can work and boot independly.
### Clustered Systems
Multiple computer systems connected via **LAN** (Local Area Network) or **WAN** (Wide Area Network), while each node is typacially a multiprocesser system.
+ **High-Availiability** — Continues even when some systems go down, the monitoring system would pick up the work and continue.
+ **Graceful Degradation** — The degree of above availiability.
+ **Fault Tolerence** — The ability to detect, diagnose and possibly correct the faliure.
#### Asymmetric Clustering
1 system from the cluster constantly monitor other systems, called the *hot-standby system*; when the system fails, the hot-standby system become the one running.
#### Symmetric Clustering
Pairs of systems are processing and also monitoring each other.
#### DLM — Distributed Lock Manager
The function that a system controls access to shared storage space within clustered systems.
#### SAN — Storage Area Network
Local storage pool assigned to each system on clustered systems, that when ever data on some host systems, the control system may order it to process.
## Operating System Operations
1. The *bootstrap program* locates and loads the operation system kernel to memory
2. **System Daemons** — System programs loaded along the kernel that also runs the whole time. After this phase, the system is fully booted.
3. The operating systems waits for either *interrupts*, *traps* (or an *exeception*) — an software generated interrupt due to errors or *system call*.
## Multiprogramming & Multiprocessing
By proper *CPU scheduling*, we are able to achieve the following ideas:
### Multiprogramming
By loading multiple *processes* on the memory and switching different between them when the CPU has to wait for the current executing process (that is, whenever it causes the CPU to idle), the CPU is kept busy and multiple programs are executed simutaneously.
### Multitasking
The process switch occurs frequently, providing a fast *respond time* to the user.
## Dual-Mode / Multimode Processing
The operating system switch between 2 modes:
+ **User Mode** — To perform user applications
+ **Kernel Mode** — Switched when user application request service, able to access and execute *previleged instructions*.
Some providers extend to more modes:
+ <u>Intel processers</u> has *rings 0~3*, which ring 0 is the kernel mode, and ring 3 is the user mode.
+ <u>ARMv8 systems</u> has 7 modes.
CPU with supports *virtualization* often has a seperate mode to indicate the **VMM** (Virtual Machine Manager) is in control.
## Timers
Could be used to signal program timeout, for example.
+ **Fixed Rate Timers** — Sends a interrupt after everey specified time lapsed.
+ **Varable Timer** — Implemented by a fixed rate timer and a counter.
Under Linux, `HZ` marks the number of interrupt sent in 1 second, and `jiffles` counts how many interrupts had been sent.
## Resource Management
### Process Management
+ **Program Counter** — Exist in each thread, points to the next instruction execute
+ **System Process** — Executes system code.
+ **User Process** — Execute user coed.
The operating system is responsible for:
+ Create/Delete both user and system processes
+ Schedule process and threads on CPUs
+ Suspend/Resume processes
+ Provide mechanism for process synchronization
+ Procidde machanism for process communication
### Memory Management
For better utilization of CPU time, multiple programs are loaded on the memory, thus make managing memory a neccessity. The operating system is responsible for:
+ Keep track of each part of memory's availiability or its owner
+ Allocate/Deallocate memory space according to need
+ Decide which data/program to move in/out of memory
### File System Management
The operating system is responsible for:
+ Create/Delete files
+ Create/Delete directories to organize files
+ Support primitives<span class="word-meaning"> (basic construction)</span> for manipulating file and directories
+ Map files to mass storage
+ Backup file on nonvolitale storage media
### Mass-Storage Management
On secondary storage devices, the operating system is responsible for:
+ Mounting/Unmounting
+ Free space management
+ Storage Allocation
+ Disk Scheduling
+ Partitioning
+ Protection
### Cache Management
Caching lets the CPU access frequently used data faster, by directily connect to the registers and store copies of data in the memory.
### I/O System Management
The operating system hides the peculiarities of the I/O system behind the *I/O subsystem*. The I/O sybsystem's components are:
+ Memory managment component that supports *buffering*, *caching* and *spooling* <span class="word-meaning">(to send data to a intermideate store)</span>
+ A general device-driver interface
+ Driver for specific hardware devices.
## Protection and Security
**Protection** is the action to limit and controlling process or user access to resources. However, it couldn't avoid attacks like faking authorized user's sigmature.
**Security** is to defent the system from attacks.
By assigning every user its unique **UID** (User ID), the operating system could recogonize usere and grant their privileges.
## Virtualization
Abstracting a single physical computer into to seperater computer environments.
**Emulation** — Simulating hardware in software.
**VMM** (Virtual Machine Manager) — Runs several guest operating systems, manage resource use and protecting from each other.
## Distributed Systems
Pschyally seperate, possible heterogeneous conputer systems that are networked so the users could access all resources within the system. The most common network protocol is *TCP/IP*.
### Network Characterization
Networks are characterized according to their distances.
1. **WAN** — Wide Area Network (E.g., A city)
2. **LAN** — Local Area Network (E.h., Within a campus)
Or, other forms:
1. **PAN** — Personal Area Network (E.g., bluetooth between phone and headset)
2. **MAN** — Metropolian Area Network (Buildings within a city)
## Computing Enviroments
+ **Traditional Computing** — The "typical office enviroment"
+ **Mobile Computing** — Using devices that are portable and lightweight
+ **Client Server Computing** — A system where **server systems** satisfies requests generated by *client systems* throught network.
+ **Peer-to-Peer Computing** — All nodes (peers) in the network can act like both client and the server.
+ **Cloud Computing** — Delivers computing, storage and applications as a <u>service</u>.
- **Public Cloud** — Availiable via the internet, grant access to whom willing to pay
- **Private Cloud** — Within company, for only the company's use
- **Hybrid Cloud** — Mix the above two
- **SaaS (Software as a Service)** — Applications availiable via the internet (E.g., Document Processers)
- **PaaS (Platform as a Service)** — Software stack ready for application use via internet (E.g., Database server)
- **IaaS (Infrastructure as a Service)** — Server/Storages abailiable via internet (E.g., storage for backup copies)