Tracing System Calls with strace and ltrace
Go deeper into troubleshooting by tracing the system and library calls a process makes, revealing exactly where it stalls or fails.
Tracing System Calls with strace and ltrace is a free Linux Command Line Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
When Metrics Are Not Enough
CPU, memory, and I/O tools tell you that something is slow. To learn why, you trace what a process actually asks the kernel to do. strace and ltrace open that window.
What strace Shows
strace records every system call: file opens, reads, network sends, and their return values, including errors.
strace ls /tmpAttaching to a Running Process
Use -p PID to trace something already running, such as a stuck service.
sudo strace -p 4567Filtering Specific Calls
-e trace= limits output to calls you care about, e.g. only file-related ones.
strace -e trace=openat,read,write cat /etc/hostnameFinding Missing Files
A classic use: see which file a program fails to open. Look for ENOENT (no such file) in the output.
strace -e trace=openat myapp 2>&1 | grep ENOENTSummarizing with -c
-c prints a profile: which syscalls consumed the most time and how often each was called.
strace -c ls -R /usr/shareTiming Calls
-T shows how long each syscall took, and -t adds timestamps, pinpointing where a process blocks.
strace -T -e trace=read myappFollowing Child Processes
-f follows forks so you trace child processes too, essential for servers that spawn workers.
strace -f -p 4567Saving Output to a File
Traces are noisy; -o writes them to a file you can grep later without cluttering the terminal.
strace -o trace.log -f myappltrace for Library Calls
While strace shows kernel calls, ltrace shows library calls like malloc or strcmp, useful for logic-level debugging.
ltrace ./myprogramA Troubleshooting Recipe
When a service hangs: attach with strace -f -p, watch for a syscall that never returns (often a blocked read or connect), and you have found the stall.
Quick Check
What kind of activity does strace primarily reveal?
Recap
You can now trace a process at the syscall level:
strace cmdor-p PIDto attach-e trace=filters,-cprofiles,-T/-ttime-ffollows children,-osaves outputltraceshows library calls
Watch for errors like ENOENT or a syscall that never returns.
Frequently asked questions
Is the “Tracing System Calls with strace and ltrace” lesson free?
Yes — the full text of “Tracing System Calls with strace and ltrace” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.
What will I learn in “Tracing System Calls with strace and ltrace”?
Go deeper into troubleshooting by tracing the system and library calls a process makes, revealing exactly where it stalls or fails. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Command Line Mastery?
No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Tracing System Calls with strace and ltrace” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Command Line Mastery lesson?
Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Disk I/O Monitoring: `iostat`, `iotop`
- Memory and CPU Performance Tools
- Advanced Logging and Troubleshooting Techniques
- Tracing System Calls with strace and ltrace