Operating Systems — Lecture 01
strcat() x4 309604 us strcpy() at known offsets 10475 us
char *str = "..." segfault char str[] = "..." works
find /usr/share 2.66 s the same command again 0.18 s
s = s + "a" O(N) keep = s; s = s + "a" O(N^2)
Same output. Same machine. Same library.
You do not need to know everything that is under you.
You need to know that something is under you, roughly what it does, and where to look when the numbers stop making sense.
ISA · system call API · C API · language API · framework API · UI
An interface is a promise about what.
It is valuable in proportion to how little it says about how.
./hello-nolibc 2 system calls 8 888 B 0.25 ms
./hello-asm 30 system calls 15 712 B 0.35 ms
./hello-c 35 system calls 16 032 B 0.35 ms
./hello-cpp 65 system calls 16 568 B 0.70 ms
python3 hello.py 6155 system calls --- 32 ms
All five end in the same write().
So why does nobody write the first one?
Management · arbitration · system services
| Family | Examples | Lecture |
|---|---|---|
| processes and threads | fork(), execve() |
06–08 |
| memory | brk(), mmap() |
03–05 |
| file I/O | open(), read(), write() |
09–10 |
| network I/O | socket(), connect() |
11 |
| IPC | pipes, signals, shared memory | 10, 12 |
man 2 syscalls · almost nothing calls them directly
User mode: cannot touch device registers, page tables, another process’s memory.
Kernel mode: can.
Across: the syscall instruction, to one address the kernel chose at boot.
A mode switch costs hundreds of nanoseconds. That is the price of the check — and the reason libc buffers.
It runs when called:
Between those, it is not running at all.
Where is it in ps?
djb2 0.032593 s per million hashes
SHA-256 0.697281 s per million hashes 21.4x
The slowness is the security property.
For storing passwords, both are wrong — SHA-256 is too fast.
An entry point, and something that starts it · an interface, and something that calls it
UI a person · API the same process · protocol a different one
Software is built in layers, and every layer is an interface that hides an implementation.
Understanding the layer below yours is what turns a surprising measurement into a decision you can defend.