Book 13 · Cheat sheet
Operating Systems
What happens underneath every program: processes and threads, memory, files, the shell and the kernel that runs it all.
Software Dictionary · softwaredictionary.org/categories/operating-systems/cheat-sheet
- 01Bootloader
- A bootloader is a small program that runs after the computer's firmware starts, loads the operating system kernel into memory, and hands control over to it.
- The bootloader runs after the firmware and before the operating system kernel.
- It finds the kernel, loads it into memory, and passes it startup options.
- On UEFI systems it lives on the EFI System Partition.
- 02Command Line InterfaceCLI
- A command line interface (CLI) is a text-based way of using a computer: you type a command with options and arguments, press Enter, and read its output.
- A CLI is a text interface: type a command, read the output.
- Commands take arguments and options such as --verbose.
- CLIs are fast, precise and easy to script and automate.
- 03Context Switch
- A context switch is when the operating system saves the state of the running thread or process and restores another one's state so it can use the CPU.
- A context switch saves one task's CPU state and restores another's.
- It is triggered by time slices ending, blocking I/O, locks, or higher-priority work.
- The direct cost is microseconds, but cold caches add hidden overhead.
- 04CPUCentral Processing Unit
- A CPU (central processing unit) is the processor that executes a program's instructions, doing the arithmetic, logic and control work all software runs on.
- The CPU executes program instructions: fetch, decode, execute.
- Clock speed in GHz is cycles per second, but not the whole story.
- Modern CPUs have multiple cores and small, fast caches.
- 05CPU Cache
- A CPU cache is a small, very fast memory on the processor that keeps copies of recently used data from RAM, so the CPU spends less time waiting for memory.
- A CPU cache is fast memory on the processor that holds copies of data from RAM.
- Caches come in levels: L1 is smallest and fastest, L3 is largest and shared.
- Data moves in cache lines, typically 64 bytes long.
- 06CPU Scheduling
- CPU scheduling is how an operating system decides which ready process or thread runs on each CPU core next, and for how long, so the processor is shared fairly.
- The scheduler is the part of the kernel that picks which task runs on each CPU core.
- Preemptive scheduling gives tasks short time slices and interrupts them when needed.
- Switching between tasks requires a context switch, which has a small performance cost.
- 07Daemon
- A daemon is a program that runs in the background without a user interface, usually started at boot, to provide a service such as logging, scheduling, or SSH.
- A daemon is a background process with no terminal or user interface.
- Daemons usually start at boot and wait for requests or events.
- Service managers such as systemd start, stop, and restart daemons.
- 08Deadlock
- A deadlock is a situation where two or more threads or processes wait forever for each other to release resources, so none of them can make progress.
- A deadlock is a cycle of parties, each waiting for a resource another one holds.
- It requires mutual exclusion, hold and wait, no preemption, and circular wait.
- Acquiring locks in a consistent order is the most common way to prevent it.
- 09Device Driver
- A device driver is software that lets the operating system control a specific piece of hardware, translating generic OS requests into device-specific commands.
- A driver translates generic operating system requests into device-specific commands.
- Most drivers run in kernel mode, often as loadable kernel modules.
- Drivers handle a device's interrupts and data transfers.
- 10File Descriptor
- A file descriptor is a small integer that a Unix-like operating system gives a process to refer to an open file, socket, pipe, or other input/output resource.
- A file descriptor is a per-process integer that refers to an open I/O resource.
- Descriptors 0, 1, and 2 are standard input, standard output, and standard error.
- Files, pipes, sockets, and devices are all accessed through descriptors.
- 11File Permissions
- File permissions are rules stored with each file that decide which users may read it, change it, or run it, enforced by the operating system on every access.
- Each file has an owner, a group, and permissions for owner, group, and others.
- The basic permissions are read, write, and execute.
- Octal notation adds read (4), write (2), and execute (1), as in 755 or 600.
- 12File System
- A file system is the part of an operating system that organizes data on a storage device into files and folders and tracks where each piece is stored.
- A file system organizes raw storage into named files and directories.
- Metadata tracks each file's size, permissions, timestamps, and data blocks.
- Journaling helps a file system recover after crashes or power loss.
- 13GPUGraphics Processing Unit
- A GPU (graphics processing unit) is a processor whose thousands of small cores run the same calculation on lots of data at once, for graphics and AI.
- A GPU has thousands of simple cores that work in parallel.
- It was built for graphics and now also powers AI.
- CUDA, from 2007, made GPUs programmable for general computing.
- 14Heap Memory
- Heap memory is the region for data a program allocates at runtime, whose size or lifetime isn't known in advance and can outlive the function that made it.
- The heap holds data allocated at runtime with flexible size and lifetime.
- Objects that outlive a function call live on the heap.
- C and C++ free it manually; Rust uses ownership; others use garbage collection.
- 15Hypervisor
- A hypervisor is software that creates and runs virtual machines, sharing one physical computer's CPU, memory, and devices among several isolated guest systems.
- A hypervisor creates, runs, and isolates virtual machines on one physical computer.
- Type 1 hypervisors run on bare metal; type 2 hypervisors run on top of an operating system.
- Hardware virtualization in modern CPUs lets guests run at near-native speed.
- 16Interrupt
- An interrupt is a signal to the CPU that an event needs immediate attention, making it pause its current work and run a special handler in the kernel.
- An interrupt makes the CPU pause its current work to handle an urgent event.
- The kernel runs a matching interrupt handler and then resumes the interrupted work.
- Hardware devices, timers, and CPU exceptions can all raise interrupts.
- 17Kernel
- A kernel is the core part of an operating system that manages the CPU, memory, and hardware devices and controls how programs get access to those resources.
- The kernel is the core of the operating system and runs the entire time the computer is on.
- It manages the CPU, memory, devices, and file systems.
- The kernel runs in privileged kernel mode; applications run in restricted user mode.
- 18Kernel Mode
- Kernel mode is the privileged CPU state in which the OS kernel has full access to hardware and memory, while ordinary programs run in restricted user mode.
- Kernel mode gives the OS kernel full access to hardware and memory.
- Applications run in restricted user mode.
- System calls, interrupts and faults switch the CPU into kernel mode.
- 19Memory Leak
- A memory leak is a bug where a program keeps holding memory it no longer needs, so its memory usage grows over time and can slow down or crash the system.
- A memory leak is memory that stays allocated even though the program no longer needs it.
- Leaks make memory usage grow steadily over time.
- Garbage collection does not prevent leaks caused by lingering references.
- 20MutexMutual Exclusion
- A mutex is a lock that lets only one thread at a time enter a critical section of code, so threads can't corrupt shared data by changing it at the same time.
- A mutex lets only one thread at a time run a critical section.
- Threads that find the mutex locked wait until it is released.
- Only the thread that locked a mutex should unlock it.
- 21Operating SystemOS
- An operating system (OS) is the core software that manages a computer's hardware, shares it out among programs and gives them a common way to use it.
- An operating system manages hardware and runs programs.
- Its kernel handles processes, memory, files, devices and permissions.
- Programs use its services through system calls.
- 22Paging
- Paging is a memory management scheme that splits memory into fixed-size pages and uses page tables to map each process's virtual pages to physical RAM.
- Memory is divided into fixed-size pages, commonly 4 KB, and RAM into frames.
- Page tables map each virtual page to a physical frame.
- The TLB caches recent translations so lookups stay fast.
- 23Process
- A process is a running instance of a program, with its own memory space, resources, and at least one thread of execution managed by the operating system.
- A process is a program in execution, identified by a process ID (PID).
- Each process has its own isolated memory space and resources.
- A process contains one or more threads that run its code.
- 24Race Condition
- A race condition is a bug where a program's result depends on the unpredictable timing of threads, processes, or requests that use shared data at the same time.
- A race condition makes the outcome depend on the timing of concurrent operations.
- Read-modify-write and check-then-act sequences are the most common causes.
- Races can happen between threads, processes, or separate web requests.
- 25RAMRandom Access Memory
- RAM (random access memory) is a computer's fast, temporary working memory, holding the programs and data in use; its contents are lost when power goes off.
- RAM is fast, temporary working memory for running programs.
- It is volatile: its contents vanish without power.
- Any address can be read directly, which is what random access means.
- 26Semaphore
- A semaphore is a synchronization tool that keeps a counter of available permits, letting up to a fixed number of threads use a resource at the same time.
- A semaphore holds a count of permits that threads acquire and release.
- A counting semaphore lets up to N threads use a resource at once.
- A semaphore has no owner, so any thread can release a permit.
- 27Shell
- A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- A shell interprets commands and asks the operating system to run them.
- Popular shells include Bash, Zsh, fish, and PowerShell.
- Pipes, redirection, and variables let you combine small commands into powerful ones.
- 28Stack Memory
- Stack memory is where a thread keeps its functions' local variables and return addresses, growing with each call and shrinking automatically on return.
- The stack holds each function call's frame: parameters, locals, return address.
- Frames are pushed on call and popped on return, so allocation is very fast.
- Each thread has its own small, fixed-size stack.
- 29sudo
- sudo lets a permitted user run a single command with root's or another user's privileges, after confirming their own password, and logs what was run.
- sudo runs one command with root's, or another user's, privileges.
- It asks for your own password and logs every use.
- The sudoers file, edited with visudo, says who may run what.
- 30Swap Space
- Swap space is an area on disk that the operating system uses as overflow for RAM, moving rarely used memory pages there when physical memory runs low.
- Swap space is disk storage used as overflow when RAM is full.
- The kernel moves rarely used pages to swap and reads them back on demand.
- Heavy swapping, called thrashing, makes a system extremely slow.
- 31System Call
- A system call is a request from a program to the operating system kernel to perform a privileged action, such as reading a file or starting a process.
- A system call is how a user-mode program asks the kernel for a privileged service.
- Each system call switches the CPU from user mode to kernel mode and back.
- Examples include open, read, write, fork, and mmap.
- 32Terminal
- A terminal is the program that shows a text interface, passing your keystrokes to a shell or command-line program and displaying the text it sends back.
- A terminal displays a text interface and forwards your keystrokes.
- Early terminals were hardware; today's are terminal emulators.
- It starts a shell, which actually runs the commands.
- 33Thread
- A thread is the smallest unit of execution an operating system can schedule, running inside a process and sharing that process's memory with other threads.
- A thread is a unit of execution that lives inside a process.
- Threads in the same process share memory, but each has its own stack.
- Multiple threads can run in parallel on a multi-core CPU.
- 34Unix
- Unix is a family of operating systems that began at Bell Labs in 1969 and whose design, with small tools, files and a shell, lives on in Linux and macOS.
- Unix began at Bell Labs in 1969 and was soon rewritten in C.
- Its philosophy: small tools that each do one thing well, combined with pipes.
- Almost everything is a file, and people work through a shell.
- 35Unix Signal
- A Unix signal is a short asynchronous notification the kernel delivers to a process to report an event, such as a stop request, an error, or an expired timer.
- A signal is a small, asynchronous notification delivered to a process.
- Common signals include SIGINT, SIGTERM, SIGKILL, and SIGHUP.
- A process can use the default action, ignore a signal, or run a handler.
- 36User Space
- User space is the restricted area where ordinary programs run, kept separate from kernel space so a buggy or malicious app cannot take down the whole system.
- User space is where applications run with restricted privileges.
- Kernel space is reserved for the kernel, which has full hardware access.
- The CPU enforces the boundary with privilege levels and memory protection.
- 37Virtual Memory
- Virtual memory is an operating system technique that gives each process its own private address space and maps it to physical RAM or disk behind the scenes.
- Each process gets its own private virtual address space.
- The MMU and page tables translate virtual addresses into physical addresses.
- Memory is managed in fixed-size pages, commonly 4 KB.