Phase 0: Man Pages as Curriculum

Objective

Learn to read man pages as your primary reference. Section 2 (syscalls) and Section 3 (library functions) are the C programmer’s documentation. No Google — man first.

Man Page Sections

Section Contents Example

1

User commands

man 1 printf (bash builtin)

2

System calls

man 2 open, man 2 read, man 2 write

3

Library functions

man 3 printf (C function), man 3 fopen

4

Special files

man 4 null, man 4 random

5

File formats

man 5 passwd, man 5 fstab

7

Concepts

man 7 signal, man 7 socket

8

Admin commands

man 8 mount, man 8 iptables

The distinction matters: man printf gives you the bash command. man 3 printf gives you the C function. Always specify the section.

Anatomy of a Man Page

man 3 fopen

Key sections to read:

  • SYNOPSIS — the function signature. This is the #include and the function prototype.

  • DESCRIPTION — what it does.

  • RETURN VALUE — what it gives back. This is where you learn error handling.

  • ERRORS — what can go wrong. Every error code, explained.

  • EXAMPLES — not always present, but gold when they are.

  • SEE ALSO — related functions. Follow these links.

Exercises

  1. [ ] man 3 printf — read SYNOPSIS. What header do you need? What does %s mean?

  2. [ ] man 3 fopen — read RETURN VALUE. What does it return on failure?

  3. [ ] man 2 open — compare with man 3 fopen. What’s different? (hint: file descriptors vs FILE pointers)

  4. [ ] man 2 read — read RETURN VALUE. Three possible results: positive, zero, negative. What does each mean?

  5. [ ] man 7 signal — skim. This is a concept page. What signals exist?

  6. [ ] man 3 intro — overview of all library functions. Skim the categories.

The printf Trap

# This is the BASH command (section 1)
man printf

# This is the C FUNCTION (section 3)
man 3 printf

Different things. The C printf is in <stdio.h> and supports %d, %s, %f, %p. The bash printf is a builtin that happens to have similar syntax. Always specify the section number.

Notes

Write your observations here.