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 |
|
2 |
System calls |
|
3 |
Library functions |
|
4 |
Special files |
|
5 |
File formats |
|
7 |
Concepts |
|
8 |
Admin commands |
|
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
#includeand 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
-
[ ]
man 3 printf— read SYNOPSIS. What header do you need? What does%smean? -
[ ]
man 3 fopen— read RETURN VALUE. What does it return on failure? -
[ ]
man 2 open— compare withman 3 fopen. What’s different? (hint: file descriptors vs FILE pointers) -
[ ]
man 2 read— read RETURN VALUE. Three possible results: positive, zero, negative. What does each mean? -
[ ]
man 7 signal— skim. This is a concept page. What signals exist? -
[ ]
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.