This post is an introduction to operating systems (OSs) and an index for other posts with topics related to operating systems.
An OS manages the computer hardware resources, so it is important to understand the different hardware components within a computer. You can read a post about computer hardware.
Operating System Functions
It is the responsibility of the operating system (OS) to handle:
- Processing management
- Resource allocation
- Memory management
- Device handling
- File management
- Networking
Processing Management
Process Execution
The instruction register (IR) or current instruction register (CIR) is the part of a CPU’s control unit that holds the instruction currently being executed or decoded.
Process State
The typical process model has 3 states:
- Waiting
- Running
- Blocked
There is also a 5 state model:
- Waiting
- Running
- Blocked
- Ready/Suspend
- Blocked/Suspend
The suspend processes imply that they have been moved to secondary memory.
You can read an external post about process state.
Each OS (such as Unix or Windows) has a more complex process state model.
Some operating systems has 3 levels of scheduling.
3 levels of scheduling:
- Short-term. Deciding which of the ready processes should be executed next on the CPU.
- Mid-term. Deciding which processes are suspended or resumed to achieve certain performance goals.
- Long-term. Deciding which jobs (set of processes) are candidates to become ready processes that will compete for the system’s resources.
CPU Scheduling Algorithms
They can be:
- Non-preemptive
- Preemptives
When it is non-preemtive, once it starts it completes the process.
When it is preemtive, it may pause the processing of a process to start or resume another one.
Process planning algorightms:
- Shortest Job First (SJF)
- First comes first served (FCFS)
- Round Robin (RR)
- Longest Job First (LJF)
- Shortest remaining time first (SRTF) / Shortest remaining processing time (SRPT)
- Longest remaining time first (LRTF)
- Highest Response Radio Next (HRRN)
- By policy
Round Robin (RR) assigns each process a quantum of time and when time finishes the planner removes it from the CPU.
SRTF is preemtive.
OS Primary Memory Management
Address Space Layout Randomization (ASLR) is a technique that increases the difficulty of performing a buffer overflow attack that requires the attacker to know the location of an executable in memory.
There are fixed and variable partitions.
There are two types of fragmentation:
- Internal
- External
Internal fragmentation occurs when part of the space within a fixed partition remains unused.
External fragmentation occurs when the space between partitions remain unused because they are too small to fit other processes.
Partition Assignment Algorithms
Partition assignment algorithms:
- First fit
- Best fit
- Worst fit
- Next fit
- Quick fit
Overlays
Overlays are a technique used to manage limited memory resources by loading only the necessary parts of a program into memory at a time. The rest of the program remains on disk and is loaded on demand. Each part of the program is known as overlay.
The technique is managed explicitly by the programmer or operating system, and there is no automatic hardware support.
It was common in earlier systems where memory was scarce, but nowadays it has been replaced mainly by paging and segmentation.
Paging
Paging is a memory management scheme that divides the process’s virtual address space into fixed-size blocks called pages. Similarly, the physical memory (RAM) is divided into fixed-size blocks called frames. Pages are mapped to frames using a page table.
It eliminates external fragmentation but may cause internal fragmentation.
The translation lookaside buffer (TLB) is a memory cache that stores the recent translations of virtual memory to physical memory.
Page Replacement Algorithms
Page Replacement algorithms:
- First In First Out (FIFO)
- Not recently Used (NRU)
- Least Recently Used (LRU)
- Not Frequently Used (NFU)
- Least Frequently Used (LFU)
- Randomly
Segmentation
Segmentation divides a program’s memory into variable-sized logical segments based on the program’s structure (e.g., code, stack, data). Each segment is defined by a base address and a limit.
It features a process segment table.
It may cause external fragmentation.
OS Secondary Memory Management
File Organization
File Organization:
- Sorted
- Static Hash
- Dynamic Hash
- Heap
Sorted is a file organization method where records are stored in a sorted order based on the value of a key field.
Static hash is a file organization method where a hash function maps a key to a specific bucket (file location). The number of buckets is fixed (static).
Dynamic hash is a file organization method where a hash function is also used but its size changes dynamically.
Heap is a storage where records are stored in no particular order, simply appended to the end of the file as they are inserted.
Hard Disk R/W Request Planning Algorithms
Hard disk R/W request planning algorithms:
- Primero en llegar
- Primero el más cercano
- Por exploración / Algoritmo del elevador
- Por exploración circular
- Asignación de espacios de almacenamiento
* Asignación contigua
* Asignación encadenada
* Asignación con índices (indexada) - Métodos de acceso en los sistemas de archivos
* Acceso secuencial
* Acceso directo
* Acceso directo indexado - Operaciones soportadas por el subsitema de ficheros
* Create / Crear
* Delete / Borrar
* Open / Abrir
* Close / Cerrar
* Read, write / Leer, escribir
* Append / Concatenar
* Seek / Localizar
* Get attributes / Leer attributes
* Set attributes / Poner atributos
* Rename / Renombrar
Device Handling
Device handling is done in an operating system by using drivers.
A device controller is the part of the device hardware that establishes the interface with the computer.
A device driver is a software programs that allows the operating system to communicate with and control hardware devices such as graphics cards, network adapters, printers, and storage devices.
Drivers are typically developed by hardware manufacturers to ensure compatibility and optimal performance with their specific hardware.
In many cases, drivers are distributed as binary blobs, particularly when they are closed source and proprietary. This means that only the compiled binary form of the driver is provided to users, and the source code is not available for inspection or modification.
On the contrary, firmware is low-level software that is embedded directly into hardware devices, typically stored in non-volatile memory such as ROM or flash memory.
Though firmware is usually stored in the ROM or flash memory, it is sometimes included in an OS kernel (such as Linux kernel) because of the following reasons:
- Bootstrapping: Some hardware devices require firmware to be loaded during the boot process in order to initialize the device and make it usable by the operating system. Inclusion of firmware within the operating system allows the system to load the necessary firmware during boot-up, ensuring that the hardware devices are properly initialized and operational.
- Driver Integration: In some cases, the firmware for a hardware device is tightly integrated with the device driver. Including the firmware with the driver allows for a more seamless integration of the hardware device with the operating system. The driver can automatically load the firmware when the device is detected, simplifying the setup process for users.
- Ease of Distribution: Distributing firmware alongside the operating system ensures that users have access to the necessary firmware for their hardware devices without needing to search for and download it separately. This can simplify the installation and setup process for users, particularly those who may not be familiar with obtaining and installing firmware manually.
- Legal and Licensing Considerations: Some hardware manufacturers distribute firmware with specific usage restrictions or licensing terms. Including the firmware with the operating system allows the distribution to comply with these legal requirements or licensing agreements. This can help avoid potential legal issues or conflicts related to the distribution of proprietary firmware.
You can read more about firmware on this post.
An Interruption Request (IRQ). There is usually a dedicated controller to handle IRQ.
Direct memory access (DMA) is a component that helps CPU to handle devices. When there is a request from the CPU to write something from the device to the main memory, the CPU informs the number of bytes to be read and the address. DMA communicates to the device controller, gets the information and writes directly to memory. This is done when it sees that the CPU is free.
You can read more about how sound server can interact with sound card in Linux OS on this post.
The I/O software stack from bottom down
- Hardware
- Interruption management
- Driver
- Device independent software
- I/O software
Operating System Generations
OS generations:
- 1945-1955
- 1955-1965
- 1965-1980
- 1980-
First generation (1945-1955) used vacuum tubes. From 1945 plugboards are used. From 1950 punched cards are used instead.
Second generation (1955-1965) used transistors. It introduces assembly languages, compilers and libraries
Third generation (1965-1980) used integrated circuits. DMA is introduced.
Four generation (1980) introduces personal computers. LSI circuits.
Operating System Models
There are different categories of operating systems.
By Layers
Monolitic
Multilayer
A 0-ring operating system runs all software within the same layer, so there is no distinction between kernel and userland.
Microkernel
By Location
Mainframe OS
Network OS
Distributed OS
By Time Management
General-purpose or time-sharing OSs.
A real-time OS minimizes response times. Examples of real-time OSs are VxWorks and QNX.
Families of Operating Systems
Popular families of operating systems:
- Unix-like OS
- Linux
- macOS
- Android
- Windows
You can read this post about Unix-like OS.
Linux
Linux or GNU/Linux is a Unix-like operating system.
You can read this post about Linux OS.
Windows
Windows is a family of operating systems developed by the American company Microsoft.
It is proprietary software.
You can read this post about Windows OS.
macOS
macOS is a family of operating systems developed by the American company Apple.
macOS X, later rebranded as macOS, is a Unix-like operating system. It is proprietary software based on Darwin OS.
You can read this post about macOS.
Android
Android is a family of operating systems developed by the American company Google and other colaborators.
Android Open Source Project (AOSP), in which most Google Android code is based, is FOSS. On the other hand, Google Android is proprietary.
You can read an introduction to Android on this post.
OS Support Lifecycle
You can read an article about OS support lifecycle on this post.