Linux Terminal Command: strace
The strace command is an essential tool in System Information & Hardware. In this tutorial, we will explore what strace does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The strace command intercepts and logs system calls made by a process and the signals it receives. It is an essential debugging tool.
Common Options & Syntax
strace [options] [arguments]
Here are the most common flags used with strace:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
strace ls
What it does: Traces all system calls made by the ls command during execution.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
sudo strace -p 1234 -e trace=openat,write -o trace_output.log
What it does: Attaches to running process 1234 (-p), records only the openat and write system calls (-e), and writes the log to a file.
⚙️ Warning & Common Pitfalls
[!WARNING]
stracecauses processes to run significantly slower (up to 10x-100x overhead). Avoid running it on production servers unless debugging critical issues.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: