strace [OPTIONS] { -p PID | PROG [ARGS] }
strace -c [OPTIONS] { -p PID | PROG [ARGS] }# Trace a running process
strace -p 1234
# Trace a new command
strace ls -la
# Follow forks and save to file
strace -ff -o trace.log myprogram
# Summary statistics only
strace -c ./myapp
# Trace specific syscalls
strace -e trace=open,read,write ./myapp-e EXPR Qualifying expression for filtering traces
Available options:
trace- Filter which syscalls to traceabbrev- Abbreviate output for syscallsverbose- Show detailed structure informationraw- Print undecoded syscall argumentssignal- Filter signals to traceread- Dump data read from file descriptorswrite- Dump data written to file descriptorsfault- Inject faults into syscallsinject- Tamper with syscall behaviorstatus- Filter by return statusquiet- Suppress informational messageskvm- Print KVM vcpu exit reasonsdecode-fds- Show file descriptor details
Format: OPTION=[!]all or OPTION=[!]VAL1[,VAL2]...
| Option | Description |
|---|---|
-E VAR=VAL--env=VAR=VAL |
Set environment variable for command |
-E VAR--env=VAR |
Remove environment variable for command |
-p PID--attach=PID |
Trace existing process (can be repeated) |
-u USERNAME--user=USERNAME |
Run command as specified user |
| Option | Description |
|---|---|
-b execve--detach-on=execve |
Detach from process after execve |
-f--follow-forks |
Follow child processes created by fork |
-ff--follow-forks--output-separately |
Follow forks with separate output files |
| Option | Description |
|---|---|
-D--daemonize[=grandchild] |
Run tracer as grandchild process |
-DD--daemonize=pgroup |
Run tracer in separate process group |
-DDD--daemonize=session |
Run tracer in separate session |
-I N, --interruptible=N
Levels:
anywhere- No signals blockedwaiting- Fatal signals blocked during syscall decode (default)never- Fatal signals always blocked (default with-o FILE)never_tstp- Fatal signals and SIGTSTP (Ctrl+Z) always blocked
-e trace=[!][?]{{SYSCALL|GROUP|all|/REGEX}[@64|@32|@x32]|none}
--trace=[!][?]{{SYSCALL|GROUP|all|/REGEX}[@64|@32|@x32]|none}Syscall Groups:
%clock- Clock and time syscalls%creds- Credential syscalls%desc- Descriptor operations%file- File operations%fstat- File status (fstat family)%fstatfs- Filesystem status (fstatfs family)%ipc- Inter-process communication%lstat- Symbolic link status%memory- Memory management%net- Network operations%process- Process management%pure- Pure syscalls (no side effects)%signal- Signal handling%stat- File status (stat family)%%stat- Alternative stat group%statfs- Filesystem status (statfs family)%%statfs- Alternative statfs group
Examples:
# Trace only open/read/write
strace -e trace=open,read,write ./app
# Trace all network calls
strace -e trace=%net ./app
# Exclude certain syscalls
strace -e trace=\!open ./app
# Trace syscalls matching regex
strace -e trace=/^read.* ./app-e signal=SET, --signal=SETTrace only specified signals (e.g., SIGTERM,SIGKILL)
-e status=SET, --status=SETAvailable statuses:
successful- Syscalls that succeededfailed- Syscalls that failedunfinished- Syscalls not yet completedunavailable- Status unavailabledetached- Process was detached
-P PATH, --trace-path=PATHTrace only syscalls accessing the specified path
| Option | Description |
|---|---|
-z--successful-only |
Show only successful syscalls |
-Z--failed-only |
Show only failed syscalls |
| Option | Description |
|---|---|
-a COLUMN--columns=COLUMN |
Alignment column for results (default: 40) |
-o FILE--output=FILE |
Write output to file instead of stderr |
-A--output-append-mode |
Append to output file |
--output-separately |
Create separate files per process (append PID) |
-v--no-abbrev |
Verbose mode - no abbreviations |
| Option | Description |
|---|---|
-s STRSIZE--string-limit=STRSIZE |
Limit string length (default: 32) |
-x--strings-in-hex=non-ascii |
Print non-ASCII strings in hex |
-xx--strings-in-hex[=all] |
Print all strings in hex |
--strings-in-hex=non-ascii-chars |
Use hex in escape sequences |
-e abbrev=SET, --abbrev=SETAbbreviate output for specified syscalls
-e verbose=SET, --verbose=SETShow detailed structure information for specified syscalls
-e raw=SET, --raw=SETPrint undecoded (raw) arguments for specified syscalls
-e read=SET, --read=SETDump data read from specified file descriptors
-e write=SET, --write=SETDump data written to specified file descriptors
-y, --decode-fds[=path]
-yy, --decode-fds=all
-e decode-fds=SET, --decode-fds=SETDetail types:
path- Show file pathsdev- Show device major/minor for block/char devicespidfd- Show associated PID for pidfdssocket- Show protocol info for socket descriptors
| Option | Description |
|---|---|
--decode-pids=pidns |
Print PIDs in strace's namespace |
-Y--decode-pids=comm |
Print command names with PIDs |
-q, --quiet=attach,personality
-qq, --quiet=attach,personality,exit
-qqq, --quiet=all
-e quiet=SET, --quiet=SETSuppressible messages:
attach- Attaching/detaching messagesexit- Process exit statuspath-resolution- Path resolution detailspersonality- Personality changesthread-execve- Thread execve messages
| Option | Description |
|---|---|
-i--instruction-pointer |
Print instruction pointer at syscall time |
-k--stack-traces |
Show stack trace for each syscall |
-n--syscall-number |
Print syscall numbers |
-X FORMAT--const-print-style=FORMAT |
Format for constants (raw/abbrev/verbose) |
-t, --absolute-timestamps[=time]Print absolute timestamp (HH:MM:SS)
-tt, --absolute-timestamps=[time,]usPrint absolute timestamp with microseconds (HH:MM:SS.microseconds)
-ttt, --absolute-timestamps=unix,usPrint Unix epoch time with microseconds
--absolute-timestamps=[[format:]FORMAT[,[precision:]PRECISION]]Formats:
none- No timestampstime- Wall clock time (default)unix- Unix epoch
Precision: s, ms, us, ns (default: seconds)
-r, --relative-timestamps[=PRECISION]Print time since previous syscall
Precision: s, ms, us, ns (default: microseconds)
-T, --syscall-times[=PRECISION]Print time spent in each syscall
Precision: s, ms, us, ns (default: microseconds)
| Option | Description |
|---|---|
-c--summary-only |
Show only statistics summary |
-C--summary |
Show both trace and statistics |
-O OVERHEAD[UNIT], --summary-syscall-overhead=OVERHEAD[UNIT]Set syscall tracing overhead (for accurate time calculations)
Units: s, ms, us, ns (default: microseconds)
-S SORTBY, --summary-sort-by=SORTBYSort options:
time- Total time (default)min-time- Minimum timemax-time- Maximum timeavg-time- Average timecalls- Number of callserrors- Number of errorsname- Syscall namenothing- No sorting
-U COLUMNS, --summary-columns=COLUMNSAvailable columns:
time-percent- Percentage of total timetotal-time- Total time spentmin-time- Minimum call timemax-time- Maximum call timeavg-time- Average call timecalls- Number of callserrors- Number of errorsname- Syscall name
Default: time-percent,total-time,avg-time,calls,errors,name
-w, --summary-wall-clockUse wall clock time instead of system time
-e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]
[:delay_enter=DELAY][:delay_exit=DELAY]
[:poke_enter=@argN=DATAN,@argM=DATAM...]
[:poke_exit=@argN=DATAN,@argM=DATAM...]
[:when=WHEN]
--inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]
[:delay_enter=DELAY][:delay_exit=DELAY]
[:poke_enter=@argN=DATAN,@argM=DATAM...]
[:poke_exit=@argN=DATAN,@argM=DATAM...]
[:when=WHEN]Parameters:
error=ERRNO- Make syscall fail with specified errnoretval=VALUE- Set specific return valuesignal=SIG- Deliver signal to processsyscall=SYSCALL- Inject different syscalldelay_enter=DELAY- Delay before syscalldelay_exit=DELAY- Delay after syscallpoke_enter- Modify arguments on entrypoke_exit- Modify arguments on exitwhen=WHEN- When to inject (see below)
Delay format: Microseconds or NUMBER{s|ms|us|ns}
When format: FIRST[..LAST][+[STEP]]
1- First call only1..5- Calls 1 through 51..5+2- Calls 1, 3, 5
-e fault=SET[:error=ERRNO][:when=WHEN]
--fault=SET[:error=ERRNO][:when=WHEN]Synonym for -e inject with default error ENOSYS
Examples:
# Make all open calls fail with ENOENT
strace -e inject=open:error=ENOENT ./app
# Delay read syscalls by 100ms
strace -e inject=read:delay_exit=100ms ./app
# Fail first 3 write calls
strace -e inject=write:error=EIO:when=1..3 ./app| Option | Description |
|---|---|
-d--debug |
Enable debug output to stderr |
-h--help |
Print help message |
-V--version |
Print version information |
--seccomp-bpf |
Enable seccomp-bpf filtering |
--tips[=[[id:]ID][,[format:]FORMAT]]Show helpful strace tips on exit
ID: Non-negative integer or random (default: random)
Format:
none- No tipscompact- Brief format (default)full- Detailed format
# Find which files a program accesses
strace -e trace=open,openat,stat ./myprogram
# Debug network issues
strace -e trace=%net -s 1000 ./myapp
# See what's blocking a process
strace -T -tt -p 1234
# Follow a daemon and all its children
strace -ff -o /tmp/daemon.log -p 1234# Get syscall statistics
strace -c ./myprogram
# Find slow syscalls (>100ms)
strace -T ./myprogram 2>&1 | grep -E '<0\.[1-9]'
# Profile with wall-clock time
strace -c -w ./myprogram
# Sort by average time
strace -c -S avg-time ./myprogram# Simulate disk full
strace -e inject=write:error=ENOSPC ./myapp
# Add network latency
strace -e inject=recv:delay_exit=100ms ./myapp
# Test error handling
strace -e fault=open:error=EACCES:when=5+ ./myapp- Use
-oto avoid mixing output: Send trace to a file to keep stdout/stderr clean - Combine with grep:
strace -e trace=open ./app 2>&1 | grep ENOENT - Watch live:
strace -p $(pidof myapp)to attach to running process - Limit string output: Use
-s 0for no string output, or increase for more detail - Focus on errors: Use
-Zto see only failed syscalls - Follow forks properly: Always use
-ffwhen tracing daemons that fork - Time analysis: Combine
-Tand-ttfor detailed timing information
strace exits with:
0if successful1if there was an error- The exit status of the traced command if different