Part 1 of 7 · 1 min read
Why this page comes third
In this module you will
- Explain what
straceshows and how it works (theptracesystem call). - Read a line of
straceoutput: call name, arguments, return value and error. - Trace a small program and say what each group of calls does (start-up, library loading, the work, exit).
- Find the failing call behind a message such as "No such file or directory".
- Count calls with
strace -c, follow children with-f, and state the cost of tracing.
Level 0 explained that a program asks the kernel for everything through system calls. strace makes those requests visible, so it shows what a program really does, whatever the source code says. It uses the file calls of Level 9, the memory calls (mmap, brk) of Levels 6 and 7, the process calls of Level 1 and the error codes of Level 10. Page 4 then uses numbers instead of traces to find performance problems, and page 5 turns to crashes and signals.
About this example About this example
Real: Every trace, count and timing was produced on a Linux test machine (kernel 6.18, glibc 2.39, strace 6.x). The two C programs were compiled with gcc -Wall -Wextra.
Scripted: The hello and loop programs are made up to give a trace with known content: one puts, and 100,000 calls to getppid.
Not real: Address values and the process IDs in the traces differ on every run. Some lines of the long hello trace are cut at the right edge. A different C library or kernel version may show different start-up calls.