8.3 KiB
Man pages — the offline documentation you'll actually use
In the exam there is no internet. Man pages are local, instant, and exam-legal — they are the only "documentation site" you get. Most students never open them. You will.
Check availability per page with man -w 2 recv; read with man 2 recv.
0. Man-page literacy (2 minutes, pays off forever)
| Section | Content | Example here |
|---|---|---|
| 1 | user commands | nc, valgrind, gdb, bash |
| 2 | system calls | socket, select, recv |
| 3 | library functions | malloc, strlen, errno, htonl |
| 5 | file formats | proc (/proc/PID/fd) |
| 7 | concepts/overviews | socket, tcp, signal |
| 8 | admin tools | ss |
man -k select(apropos) — search by keyword when you don't know the page name.man 2 select— force a section when names collide (printf(1)shell vsprintf(3)C).- Inside the pager:
/RETURN VALUEsearch,nnext hit,Gbottom,qquit. - Read the bottom half first. RETURN VALUE, ERRORS, NOTES, EXAMPLES, SEE ALSO are where the answers are. Skip HISTORY/BUGS/COLOPHON.
- Plain output you can grep:
man -P cat 2 select | col -b | less man -P cat 2 select | col -b | sed -n '/RETURN VALUE/,/^ERRORS/p' - Save a page offline for your notes:
man -P cat 2 recv | col -b > recv.txt.
1. The core 10 (if you read nothing else)
| # | Page | Why it matters for mini_serv |
|---|---|---|
| 1 | man 2 select_tut |
A full tutorial with a working select-server example. The closest thing to a solved mini_serv in the docs |
| 2 | man 2 select |
The exact contract: nfds, the three sets, destructive overwrite, return values |
| 3 | man 7 socket |
What AF_INET / SOCK_STREAM are; socket options (SO_REUSEADDR) |
| 4 | man 2 socket · man 2 bind · man 2 listen · man 2 accept |
The server lifecycle; backlog; accept queue; why accept returns a new fd |
| 5 | man 2 recv · man 2 send |
Return values (0 = EOF!), flags, partial sends |
| 6 | man 2 close |
Cleanup; NOTES explains close vs shutdown |
| 7 | man 7 signal |
The SIGPIPE default action (exam exit code 141) |
| 8 | man 3 errno · man 3 perror · man 3 strerror |
Decoding every -1: EADDRINUSE, EBADF, EINTR, EPIPE… |
| 9 | man 8 ss · man 1 nc |
Seeing LISTEN/ESTABLISHED and talking to your server |
| 10 | man 5 proc |
/proc/PID/fd — your fd-leak microscope |
2. Full curated index (grouped)
A. Sockets — the server's body
| Page | What you learn | Gym link |
|---|---|---|
man 2 socket |
domain/type/protocol; fd returned | Station 3 |
man 2 bind |
tying address+port; EADDRINUSE, EACCES |
Station 4 |
man 2 listen |
backlog = queue of completed-but-unaccepted connections | Station 4, explore/02 |
man 2 accept |
dequeue one connection; returns a new fd; when it can fail | Station 7 |
man 2 connect |
the client side (what nc does) |
context only |
man 2 send |
partial sends, EPIPE, MSG_NOSIGNAL |
Station 10, libc-ref §6 |
man 2 recv |
0 = EOF, -1 = error, no message boundaries |
Station 9 |
man 2 close |
releasing fds; close-vs-shutdown notes | Station 11 |
man 2 shutdown |
half-close semantics (not needed, but explains what peers do) | optional |
man 2 setsockopt |
SO_REUSEADDR — why a restart sometimes says "Address already in use" |
debugging |
man 2 getsockname · man 2 getpeername |
identifying endpoints (useful trace prints) | debugging |
man 7 ip |
sockaddr_in, sin_addr, sin_port layout |
Station 3 |
man 3 inet_addr · man 3 inet_ntoa · man 3 inet_pton |
address ↔ text (127.0.0.1 ↔ bytes) — not required, great for debug prints |
optional |
man 3 htons → byteorder(3) |
htons/htonl/ntohs/ntohl in one page | Station 3 |
man 7 tcp |
TCP behavior, socket options, state names | fundamentals §5 |
B. Waiting room — select and friends
| Page | What you learn | Gym link |
|---|---|---|
man 2 select |
sets, nfds = max+1, destructive overwrite, EINTR/EBADF |
Station 6 |
man 2 select_tut |
worked example server — read this one with coffee | Station 6 |
man 2 poll |
the fd-array alternative (not allowed; helps you understand why select is clunky) | optional |
man 7 epoll |
how real servers scale (not exam material) | optional |
C. Errors and signals
| Page | What you learn | Gym link |
|---|---|---|
man 3 errno |
the errno mechanism + full name list | debugging §8 |
man 3 perror · man 3 strerror |
printable error strings (dev-only here) | debugging §8 |
man 7 signal |
every signal + default action; SIGPIPE kills by default | libc-ref §6 |
man 7 signal-safety |
why async-signal-safety matters (signal() isn't in this exam) | optional |
man 3 exit |
exit status conventions, flushing | Station 2 |
D. Bytes, strings, memory, formatting (section 3)
| Page | Use in mini_serv |
|---|---|
man 3 strlen |
lengths; UB if unterminated |
man 3 strcpy · man 3 strcat |
copies/appends used by the given helpers |
man 3 strcmp · man 3 strstr |
allowed; rarely needed |
man 3 memset · man 3 bzero |
zeroing sockaddr_in; the exam main.c uses bzero |
man 3 malloc · man 3 calloc · man 3 realloc · man 3 free |
per-client buffers; free(NULL) is fine |
man 3 sprintf |
building "client %d: %s" (size it: strlen + 64) |
man 3 snprintf |
the safe variant (learning; not in the allowed list) |
man 3 atoi |
port parsing; no error detection |
E. Debugging & observation (the other half of the skill)
| Page | What it gives you |
|---|---|
man 8 ss |
-t -l -n -p flags; listening/established states; filters |
man 1 nc |
-N (close after stdin EOF), -v, -l; what "connected" means |
man 5 proc |
/proc/PID/fd (fd tables), status, maps — search for "fd" |
man 1 valgrind |
leak-check and fd-tracking flags |
man 1 gdb |
-ex run -ex bt, attaching, batch mode |
man 1 top · man 1 ps |
CPU% and process state (the 100%-CPU signature) |
man 1 bash |
the grader's /dev/tcp/host/port trick is documented here (REDIRECTIONS) |
man lsof |
open files/fds per process (alternative to /proc) |
man 7 man-pages |
conventions + which section to look in |
man 2 intro · man 2 syscalls |
what syscalls exist at all (check the allowed list) |
Missing on this machine (checked): strace(1) and netstat(1) pages — strace isn't
installed either; use ss(8) and gdb/valgrind instead. Note errno is section 3, and
htons/htonl live in byteorder(3), not section 7.
3. Suggested reading paths
Path A — sockets literacy (45 min, day 1)
7 socket → 2 socket → 2 bind → 2 listen → 2 accept → 2 connect (skim) →
2 recv → 2 send → 2 close → 2 select_tut (read fully) → 7 signal (SIGPIPE row).
Path B — debugging kit (20 min, day 2)
8 ss → 1 nc → 5 proc (fd part) → 3 errno → 3 perror → 1 valgrind → 1 gdb.
Path C — exam-eve refresher (10 min, day 3)
2 listen (backlog) → 2 accept (new fd) → 2 recv (0 = EOF) → 2 select (nfds,
overwrite) → 7 signal (SIGPIPE) → 3 exit (status codes).
4. Power moves
man -k "file descriptor" # when you don't know the page name
man -P cat 2 accept | col -b | sed -n '/RETURN VALUE/,/^ERRORS/p'
man -P cat 7 signal | col -b | grep -A2 SIGPIPE # default action, one line
man -P cat 2 listen | col -b | grep -B2 -A8 backlog # the queue explanation
man 2 socket # then follow SEE ALSO → socket(7) → tcp(7)
SEE ALSO at the bottom of every page is a curated reading list. Following
socket(2) → socket(7) → tcp(7) → ip(7) teaches you the whole network stack in four hops,
in the order the docs intend.
5. How to practise man pages (yes, practise)
- Open
man 2 recv, cover the screen, and answer: what are the three return cases? man 2 select— findnfdsand explain the destructive-overwrite warning out loud.man 7 signal— find SIGPIPE's default action and connect it to exit code 141.man 8 ss— find the flag that shows the owning process (-p), use it on your server.man 5 proc— find the fd directory and use it in a leak test.
If you can do those five without scrolling in panic, you're ready for any error the exam throws at you.