An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between programs and the computer hardware, although the application code is usually executed directly by the hardware and frequently makes system calls to an OS function or is interrupted by it.
CPU Architecture Overview
CPU (Central Processing Unit) architecture refers to the design and organization of a computer’s main processor, which is responsible for executing instructions, performing calculations, and controlling data flow within a computer system.
Key Components of CPU Architecture
Arithmetic Logic Unit (ALU): Executes arithmetic and logical operations. It performs calculations, comparisons, and decision-making tasks within the CPU.
Control Unit (CU): Directs the operation of the processor, orchestrating the fetching, decoding, and execution of instructions. It manages the flow of data between the CPU and other components.
Registers: Small, fast storage locations within the CPU, used to hold data, instructions, addresses, and intermediate results during processing. Examples include the program counter (PC), accumulator (ACC), memory address register (MAR), and memory data register (MDR).
Cache: High-speed memory within the CPU that stores frequently accessed data and instructions to speed up processing.
Buses: Communication pathways (address, data, and control buses) that transfer information between the CPU, memory, and peripherals.
x86/x86-64 (CISC)
Description: The x86 family is based on a Complex Instruction Set Computing (CISC) architecture, originally developed by Intel. x86-64 (also known as AMD64 or Intel 64) extends this to 64-bit processing.
Use Cases: Predominantly used in desktop PCs, laptops, and servers.
Key Features: Variable instruction length, register-memory operations, and support for a wide range of applications.
ARM (RISC)
Description: ARM is a family of Reduced Instruction Set Computing (RISC) architectures, designed for efficiency and scalability.
Use Cases: Widely used in smartphones, tablets, embedded systems, and increasingly in laptops and servers.
Profiles: ARM offers different profiles for various needs:
A-profile: High performance for applications like PCs, servers, and smart devices.
R-profile: Real-time systems such as automotive and medical devices.
M-profile: Microcontrollers for IoT and wearables.
Key Features: Fixed-length instructions, load/store architecture, and energy efficiency.
PowerPC (RISC)
Description: Another RISC architecture developed by IBM, Apple (historically), and others.
Use Cases: Used in servers, embedded systems, and historically in Apple Macs.
Key Features: High performance, scalability, and reliability.
MIPS (RISC)
Description: A RISC architecture developed by MIPS Technologies.
Use Cases: Embedded systems, networking equipment, and some consumer electronics.
Key Features: Simplicity, low power consumption, and efficient pipeline design.
TriCore (RISC)
Description: A RISC-based architecture from Infineon, designed for automotive and industrial applications.
Use Cases: Real-time and safety-critical systems.
Key Features: Integrated microcontroller and DSP capabilities.
Instruction Set Architecture (ISA) styles define how a processor’s instructions are structured and executed, serving as the interface between software and hardware. The two most prominent ISA styles are Reduced Instruction Set Computer (RISC) and Complex Instruction Set Computer (CISC), but there are also other notable styles.
Both UEFI (Unified Extensible Firmware Interface) and BIOS (Basic Input/Output System) are firmware interfaces that initialize your computer’s hardware and launch the operating system when you power on your PC.
Faster Boot Times: UEFI initializes hardware more efficiently, resulting in quicker startup136.
Larger Drive Support: UEFI supports booting from hard drives larger than 2 TB, up to 9.4 zettabytes, using the GUID Partition Table (GPT).
More Security Features: UEFI includes Secure Boot, which checks that only trusted software loads during startup, protecting against malware and unauthorized OS modifications.
Better User Interface: UEFI offers a graphical interface with mouse and touch support, making it easier to navigate and configure.
Remote Diagnostics and Networking: UEFI can boot over a network and supports remote troubleshooting.
Simplicity: BIOS is simpler and more modular, which can make it easier to work with for advanced bootloaders or legacy systems.
Compatibility: BIOS is still needed for running older operating systems or hardware that does not support UEFI.
Most modern computers manufactured after the late 2000s come with UEFI firmware. UEFI is generally recommended for new systems due to its speed, security, and support for large drives. BIOS is now considered legacy technology and is being phased out, but it remains available for compatibility with older hardware and operating systems.
The booting process of a computer is the sequence of steps that occur from the moment the computer is powered on until the operating system (OS) is loaded and the user can interact with the system. Here is a typical overview of the booting process:
1. BIOS/UEFI Initialization
When the computer is powered on, the Basic Input/Output System (BIOS) or Unified Extensible Firmware Interface (UEFI) firmware initializes and checks the hardware components.
The firmware is stored in ROM and is responsible for hardware initialization and preparing the system to load the operating system.
2. Power-On Self-Test (POST)
The BIOS/UEFI runs the POST, a series of diagnostic tests to ensure that essential hardware components (CPU, RAM, storage devices, etc.) are functioning correctly.
If issues are detected, POST may generate error messages or beep codes.
3. Boot Device Selection
After successful POST, the firmware checks the boot order configured in its settings to determine which device (hard drive, SSD, USB, CD/DVD) contains the bootloader.
The system searches for a bootable device and attempts to load the bootloader from it.
4. Bootloader Execution
The bootloader (such as GRUB for Linux or Windows Boot Manager for Windows) is a small program that loads the operating system kernel into memory.
In legacy systems, the bootloader is typically found in the Master Boot Record (MBR); in modern systems, it may be located in the EFI System Partition (ESP).
5. Operating System Kernel Loading
The bootloader loads the OS kernel and essential drivers into memory.
The kernel initializes hardware and software components, mounts the root file system, and starts system processes.
6. System Initialization and User Authentication
The operating system completes initialization by launching system services, setting up the user environment, and presenting the login screen.
The user logs in, completing the booting process.
Types of Kernels
There are five main types of kernels in operating systems, each with distinct architectures and design philosophies:
Monolithic Kernel
All operating system services—such as process management, memory management, file systems, and device drivers—run in the same address space as the kernel. This results in high performance due to fast communication between services, but a bug in any part can crash the entire system. Examples include Linux and Unix.
Microkernel
Only the most essential services (like inter-process communication and memory management) run in the kernel space. Other services, such as device drivers and file systems, run as user-space processes. This improves stability and security but can reduce performance due to increased inter-process communication. Examples include MINIX and QNX.
Hybrid Kernel
Combines features of both monolithic and microkernels. Some services run in kernel space for performance, while others run in user space for modularity and stability. Examples include Microsoft Windows NT-based systems and macOS (XNU).
Nanokernel
The smallest type of kernel, providing only the most basic hardware abstraction. Most services are moved out to user space or to other layers. Used mainly in embedded systems or devices with very limited resources.
Exokernel
Provides only the minimum necessary hardware protection and resource management. Applications are given more direct access to hardware, allowing for application-specific customization. Exokernels are designed for high flexibility and are used in research and specialized environments.
Operating systems have a number of different layers. Each of these layers has its own privileges. We use protection rings term while mentioning this system. Operating systems manage computer resources, like processing time on the CPU and accessing the memory. Since computers run more than one software process, this will bring some issues. Protection rings are one of the key solutions for sharing resources and hardware.
So, what happens is that processes are executed in these protection rings, where each ring has its own access rights to resources. The central ring has the highest privilege. The outer ones have fewer privileges than the inner ones. The figure below represents the protection rings for x86 processor architecture which is one of the common processor architectures.
As we’ve seen, it has four rings numbered from 0 to 3:
There are some advantages and benefits to implementing protection rings in the OS.
First and foremost, it protects the system against crashes. For example, an application that we use in our computers can freeze or crash, however, we can recover them by restarting the application. Errors like these in higher rings are recoverable.
Because these programs don’t have direct access to memory or CPU. Only ring 0, the kernel has direct access to hardware resources. In this way, we can restart an application without losing data or causing an error in the CPU.
Furthermore, protection rings offer increased security. For example, a process can require some instructions that require more CPU resources. In such a case, this process must request permission from the OS. The OS can decide whether grant the request or deny it. This process protects the system from malicious behavior.
The kernel, which is at the heart of the operating system and has access to everything, can access Ring 0. The code that runs here is said to be in kernel mode. Kernel-mode processes have the potential to affect the entire system. If something goes wrong here, the system would most likely crash. Because this ring has direct access to both CPU and system memory.
User processes running in user mode have access to Ring 3. Therefore, this is the least privileged ring. This is where we’ll find the majority of our computer applications. Since this ring doesn’t have any access to the CPU or memory, any instructions involving these must be passed to ring 0.
On the other hand, rings 1 and ring 2 offer unique advantages that ring 3 lacks. The OS uses ring 1 to interact with the computer’s hardware. This ring would need to run commands such as streaming a video through a camera on our monitor. Instructions that must interact with the system storage, loading, or saving files are stored in ring 2.
These rights are known as input and output permissions because they involve transferring data into and out of working memory, RAM.
In ring 2, for example, loading an Excel file document from storage. In such a case, ring 3 will be responsible for editing and saving the data.
Most of the CPU architectures such as x86 include some form of protection rings. However, some of the operating systems such as Linux, macOS, and Windows doesn’t fully utilize these feature. While Linux and Windows use only ring 0 and ring 3, some other operating systems can utilize three different protection levels.
On the other hand, ARM 7 which is one of the other common processor architectures implements three privilege levels: application, operating system, and hypervisor. ARM 8 implements four protection levels. In addition to existing levels in ARM 7, it adds a secure monitor level.
As we’ve discussed, ring 0 and ring 3 are the essential levels, and ring 1 and ring 2 are optional protection levels.
A process is an instance of a program running in a computer. It is close in meaning to task , a term used in some operating systems. In UNIX and some other operating systems, a process is started when a program is initiated (either by a user entering a shell command or by another program).
Like a task, a process is a running program with which a particular set of data is associated so that the process can be kept track of. An application that is being shared by multiple users will generally have one process at some stage of execution for each user.
A process can initiate a subprocess, which is a called a child process (and the initiating process is sometimes referred to as its parent ). A child process is a replica of the parent process and shares some of its resources, but cannot exist if the parent is terminated.
Processes can exchange information or synchronize their operation through several methods of interprocess communication ( IPC ).
A process control block (PCB) is a data structure used by computer operating systems to store all the information about a process. It is also known as a process descriptor.
When a process is created (initialized or installed), the operating system creates a corresponding process control block.
Information in a process control block is updated during the transition of process states.
When the process terminates, its PCB is returned to the pool from which new PCBs are drawn.
Each process has a single PCB.
Memory Management
Memory management is the process of controlling and coordinating computer memory, assigning portions called blocks to various running programs to optimize overall system performance.
Memory management resides in hardware, in the OS (operating system), and in programs and applications.
In hardware, memory management involves components that physically store data, such as RAM (random access memory) chips, memory caches, and flash-based SSDs (solid-state drives).
In the OS, memory management involves the allocation (and constant reallocation) of specific memory blocks to individual programs as user demands change.
At the application level, memory management ensures the availability of adequate memory for the objects and data structures of each running program at all times.
In computer security, a sandbox is a security mechanism for separating running programs, usually in an effort to mitigate system failures or software vulnerabilities from spreading.
It is often used to execute untested or untrusted programs or code, possibly from unverified or untrusted third parties, suppliers, users or websites, without risking harm to the host machine or operating system.
A sandbox typically provides a tightly controlled set of resources for guest programs to run in, such as storage and memory scratch space.
Network access, the ability to inspect the host system or read from input devices are usually disallowed or heavily restricted.
Why was the print command included in every programming language?