System
strace
strace commands for system call tracing and debugging.
30 commands
Windows
MacOS
Linux
#debugging
#tracing
Basic Tracing
Trace all system calls of a command
strace ls
Trace child processes too
strace -f ./server
Trace children to separate log files
strace -ff -o log ./server
Show timestamp for each syscall
strace -t ls
Show time spent in each syscall
strace -T ls
Show syscall summary statistics
strace -c ls
Filtering
Trace specific syscalls
strace -e trace=open,read,write ls
Trace only network syscalls
strace -e trace=network curl url
Trace only file-related syscalls
strace -e trace=file ls
Trace process-related syscalls
strace -e trace=process bash
Trace memory-related syscalls
strace -e trace=memory ./app
Trace specific signals
strace -e signal=SIGTERM ./app
Process Attachment
Attach to a running process by PID
strace -p 1234
Attach and trace child processes
strace -p 1234 -f
Attach and filter syscalls
strace -p 1234 -e trace=write
Attach to process by name
strace -p $(pidof nginx)
Output Options
Write output to a file
strace -o trace.log ls
Per-thread output files
strace -o trace.log -ff ./server
Show longer string arguments
strace -s 1024 ls
Print non-ASCII strings in hex
strace -x ls
Print file descriptor paths
strace -y ls
Print IP and port for sockets
strace -yy ls
Statistics
Count time, calls, and errors per syscall
strace -c ls
Count and show regular output combined
strace -C ls
Sort summary by time spent
strace -c -S time ls
Sort summary by number of calls
strace -c -S calls ls
Use wall clock time for summary
strace -w -c ls
Quick Commands
Trace all system calls including child processes
strace -f ./server
Trace only network-related system calls
strace -e trace=network curl url
Attach to a running process by PID
strace -p 1234