OSOperating Systems · Lesson 7 of 7
OS Cheatsheet
Processes, memory, files, and the commands to inspect them — one page.
Text
── Core concepts ────────────────────────
kernel: privileged code managing everything
user/kernel mode: CPU-enforced protection boundary
syscall: the only door into the kernel
(open, read, write, fork, execve, socket, ~350 total)
process: running program + its own virtual memory,
file descriptors, PID, parent
thread: execution stream INSIDE a process;
shares memory with siblings (fast, race-prone)
fork+exec: how every process is born (Unix)
signals: SIGINT (Ctrl+C), SIGTERM (please die),
SIGKILL (-9, unblockable), SIGHUP (terminal gone)
scheduler: timer interrupt every few ms,
save registers, pick next thread, restore, resume
-> the illusion of everything running at once
blocked threads cost no CPU (waiting on IO/locks)
── Memory ───────────────────────────────
virtual memory: per-process address space, MMU
translates via page tables, 4KB pages
page fault: minor (lazy alloc, fine) vs
major (from disk, slow) vs segfault (illegal)
copy-on-write: fork copies nothing until writes
OOM killer: RAM exhausted -> biggest process dies
layout: [code | globals | heap -> ... <- stack]Bash
# ── Inspection commands ─────────────────
ps aux # all processes
top / htop # live view
pstree # parent/child tree
kill PID; kill -9 PID # SIGTERM / SIGKILL
free -h # RAM ('available' includes cache)
cat /proc/PID/status # kernel's view of a process
strace CMD # every syscall it makes
lsof -p PID # its open files/sockets
dmesg | tail # kernel messages
nice -n 10 CMD # run at lower priority
# ── Files & permissions ─────────────────
# inode = the file (metadata+data); name = just a link
# fd 0 stdin, 1 stdout, 2 stderr
ls -li # inode numbers
stat file # all metadata
chmod 644 f # rw-r--r-- (u/g/o × rwx)
chmod u+x script.sh
ln target hardlink; ln -s target symlink
df -h; du -sh dir # disk usage
# ── Concurrency rules ───────────────────
# race: unsynchronized shared writes -> lost updates
# fix: locks / atomics / share nothing
# deadlock: cyclic lock wait
# fix: always acquire locks in the same order
# ── Containers ≠ VMs ────────────────────
# namespaces (private view of PIDs/net/fs)
# + cgroups (CPU/RAM caps) = container
# same kernel, millisecond startup; VM = whole OS