strace
strace cheatsheet by Thamizhiniyan C S
Introduction
strace is a command-line linux tool used to trace system calls and signals
Use Cases:
Debugging Programs
Troubleshooting Programs
Intercept System calls by a process
Record system calls by a process
Signals received by a process
Trace running processes
Installation
Syntax
strace [OPTIONS] [EXECUTABLE_FILE]
Important Flags
Flag | Description |
---|---|
| count time, calls, and errors for each syscall and report summary |
| like -c, but also print the regular output |
| trace only specified syscalls |
| trace only the specified set of signals. print only the signals from SET |
| print only system calls with the return statuses in SET |
| Follow threads and child processes that are created. |
| print relative timestamp |
| print instruction pointer at time of syscall |
| print time spent in each syscall [precision: default is microseconds] |
| print absolute timestamp of each system call (wall clock time) |
| send trace output to FILE instead of stderr |
| trace process with process id PID, may be repeated |
| run command as USERNAME handling setuid and/or setgid |
| Print [size] characters per string displayed. This is useful if you are trying to trace what a program is writing to a file descriptor. |
TRACE values
open, close, write, network, signal
STATUS values
successful, failed, unfinished, unavailable, detached
PRECISION values
s, ms, us, ns
Examples
Command | Description |
---|---|
Trace system calls of the `ls` command. | |
Count the number of system calls. | |
Trace only the `write` system calls of the `ls` command. | |
Trace network-related system calls of the `nc` command. | |
Trace signal-related system calls of the `nc` command. | |
Print the timestamp of each system call. | |
Print time spent on each system call. | |
Print wall clock time of each system call. | |
Print the instruction pointer of each system call. | |
Trace a running process by PID. | |
Trace a running process by PID. | |
Trace a running process and its threads. | |
Trace a running process, print first 80 characters of strings. | |
Trace a program. | |
Trace a program and its threads. | |
Trace a program, print first 80 characters of strings. | |
To exclude futex calls | |
Trace specific system calls (open, read, write) for a program and its threads. |
References
https://www.geeksforgeeks.org/strace-command-in-linux-with-examples/
Last updated