8.9 KiB
Exam Rank 06 — mini_serv training gym
Goal: walk into Exam Rank 06, get mini_serv, submit once, pass. Cold recall — no guessing.
What the exam actually is (confirmed)
- One file:
mini_serv.c. Aselect()-based multi-client chat server on127.0.0.1:<port>. - The exam gives you a
main.cattachment with socket boilerplate + two helpers (str_join,extract_message). You are expected to reuse those helpers. - Grading is scripted, automated, byte-exact: one listener client is connected, then a
series of short-lived clients connect / send / disconnect, and the output the listener
received is
diff-ed against an expected trace. (The real test is intester/grademe/.) - Window: ~2–4 h. No internet. Only the allowed functions from the subject.
⚠️ Campus caveat. In the updated exam format some students get
mini_db(C++98 key-value server) instead — sometimes as "level 2" of the same exam. Ask a senior at your campus exactly what exam 06 serves there. 80% of this training (select loop, line buffering, broadcast, clean disconnect) transfers to mini_db; if your campus uses it, tell me and I'll extend this gym.
What exactly gets checked (ground truth from the graders)
- No argument → stderr
Wrong number of arguments\n, exit status 1. - Bind failure → stderr
Fatal error\n, exit status 1. - Client N connects → every other connected client gets
server: client N just arrived\n. The newcomer gets nothing for itself. - Client N sends data → every other client gets
client N:+ every complete\n-terminated line — one prefix per line, even if one packet contained several lines. - An incomplete line (no
\nyet) is held in a per-client buffer… and dropped if the client disconnects — never flushed. \x04(Ctrl-D byte) is plain data, not EOF. Onlyrecv() <= 0means disconnect.- Client disconnects → everyone else gets
server: client N just left\n. - Ids increment forever (
0, 1, 2, …), never reused. - It must survive a 364 KB single line and a 10 KB line with no newline (both are in the test).
- No memory / fd leaks. Non-blocking: only call
recv/sendafterselectsaid "ready". - Only listen on
127.0.0.1(htonl(2130706433)). No#definein the file.
Files in this gym
| Path | What it is |
|---|---|
subject/subject.en.txt |
The exam subject (verbatim, from the official attachment) |
subject/main.c |
The helper file the exam gives you |
cheatsheet.md |
The 8 moves + the 15 traps. Read once, re-read after every attempt |
walkthrough.md |
Code block → line-by-line → real captured behavior for every station (with probes) |
exam-pack.md |
The desert-island file: exam subject + main.c verbatim, full stage plan, debug ladder, checklist, man-page excerpts |
diagrams.md |
15 diagrams from scratch: processes, fd table, address, door, state, select loop, accept, pipeline, disconnect, ids, ownership, errors, session |
exam-answer/mini_serv.c |
The simplest passing implementation (proven 13/13 + Grademe) |
exam-answer/explained.md |
Every variable, function, expression and ownership rule in that file |
subject/main.annotated.c |
The exam's main.c, annotated: keep the helpers, rewrite main() |
exam-card.md |
One screen for the 5 minutes before you enter |
fundamentals.md |
What fds, sockets, TCP streams and select() really are — with runnable experiments |
libc-reference.md |
Every syscall/libc call used by mini_serv, individually: args, returns, errno, exam pattern, traps |
man-pages.md |
Curated offline man-page index + reading paths + "power moves" |
debugging.md |
Debugging toolkit (gdb/valgrind/ss), the symptom→cause table, a 60-second triage checklist |
explore/ |
Four tiny toy programs that make the fundamentals visible |
drills/drills.md |
D1…D8 training program, scoring, 3-day crash plan |
templates/mini_serv.skeleton.c |
Fill-in skeleton (compiles, TODOs where the meat is) |
reference/mini_serv.c |
A known-good solution. Only for diffing AFTER a timed attempt |
reference/variant_friend.c |
Community variant (sets + one-event-per-wakeup style), validated by this gym's graders |
tester/mini_serv_tester.py |
Fast offline behavioral tester (13 checks, edge cases) |
tester/grademe/ |
The real exam-style test suite (exact diff) |
tester/check.sh |
One command: strict compile + behavioral tester + real grademe diff |
sandbox/ |
Your exam simulation. You write sandbox/rendu/mini_serv/mini_serv.c |
Commands
# check your attempt (compile with -Wall -Wextra -Werror + behavior + real grademe diff):
bash tester/check.sh
# fast behavioral suite only (needs a compiled binary):
cc -Wall -Wextra -Werror sandbox/rendu/mini_serv/mini_serv.c -o sandbox/mini_serv
python3 tester/mini_serv_tester.py sandbox/mini_serv
# real grademe runner only:
cd sandbox && bash .system/grading/tester.sh
# pass -> sandbox/.system/grading/passed exists
# fail -> sandbox/traceback contains expected-vs-yours
# manual testing with netcat (3 terminals):
cc -Wall -Wextra -Werror sandbox/rendu/mini_serv/mini_serv.c -o sandbox/mini_serv
./sandbox/mini_serv 8081 # terminal 1
nc 127.0.0.1 8081 # terminal 2 (listener)
nc 127.0.0.1 8081 # terminal 3 (type "hello" + Enter; terminal 2 shows "client 1: hello")
# Ctrl-D in terminal 3 → terminal 2 shows "server: client 1 just left"
The plan
7-day plan (default)
| Day | Work |
|---|---|
| 1 | Read the subject + cheatsheet.md. Drill D1 (requirement recall), D2 (boilerplate blast ×3), D3 (buffer brains ×2) |
| 2 | D4 (join/leave + ids), then D5: first full from-blank attempt under timer → check.sh → diff vs reference/ |
| 3 | Fix the "what I missed" list. D5 again. Target: all green |
| 4 | D6: full attempt ≤ 90 min, all green. Then D7 chaos scenarios |
| 5 | D5/D6 again — two clean runs in a row? |
| 6 | D8: exam sim — fresh dir, vim, 2 h, no notes, then grade yourself |
| 7 | Light repetition (D2/D3 from memory), read cheatsheet traps once, rest. |
3-day crash plan (exam in ≤3 days, ~2 h/day)
| Block | Work |
|---|---|
| Day 1 · 20 min | Read subject/subject.en.txt + cheatsheet "8 moves". Then D1 (write the ground truths from memory) |
| Day 1 · 80 min | drills/typing-script.md Stage A→F, live nc checkpoints. Guided reading allowed this first rep |
| Day 1 · 20 min | D2 rep 2 (blank) + Stage D case table from memory |
| Day 2 · 15 min | Warm-up: Stage C from blank, < 15 min |
| Day 2 · 75 min | D5: full attempt from blank, timer on. Then check.sh + diff vs reference/ + write "what I missed" |
| Day 2 · 30 min | Fix the missed bits: re-drill only failing stages ×3 |
| Day 3 · 30 min | D5/D6 again from blank, target ≤ 60 min, all green |
| Day 3 · 30 min | D7 chaos (check.sh, then tester/mini_serv_tester.py --quick loops) |
| Day 3 · 45 min | D8-lite: fresh dir, only subject + main.c open, type the whole file, then grade |
| Day 3 · 15 min | Read cheatsheet traps once. Stop. Sleep. |
If Day 3's cold run is not green, take the exam only if you must — a failed attempt is information, not the end. But if you can wait one more day and get one more green, wait.
Readiness rule
Two consecutive full attempts written from a blank file, all green, under 2 h = ready. Not "I understand it". Not "I did it once". Twice, in a row, cold.
Rules of the gym
- During any timed attempt: no internet, no notes, no
reference/, vim only — same as the exam. - After the attempt:
check.sh→ then diff your file againstreference/line by line and write down every difference you missed (that list is your real study material). - Never copy-paste during practice. Typing the patterns is the point.
reference/is for post-attempt study and for keeping the test harness honest. It is not an exam asset. Exam day you write your own code.
Exam-day playbook
- Read the subject twice. Copy the exact strings (
"Wrong number of arguments\n","Fatal error\n","server: client %d just arrived\n", …) into your file as you go. - Found the
main.cattachment? Open it in a split / second tab. Copystr_join+extract_messageverbatim — they're free wins. - Build in this order: args check → socket/bind/listen → fd_set loop → accept + arrivals →
recv + buffer + line extract + relay → disconnect + departures. Test with a second
terminal after each layer (
nc), don't wait for the end. - Leave 30 min at the end for
ncsanity + re-reading the subject + submission. - Submit early, submit again after fixes if the exam shell allows. A submitted partial program beats a perfect unsent one.
- Panic costs more than bugs. You have drilled this. Type what you drilled.