Seven strace examples to debug the execution of a program in Linux.

# To start tracing a specific process by its PID
strace -p <pid>

# To trace a process and filter output by system call
strace -p <pid> -e <system call name>

# To count time, calls, and errors for each system call and report a summary on program exit.
strace -p <pid> -c

# To trace the execution of the program (ls)
strace ls

# To trace a specific system calls in an executable using option "-e"
strace -e open ls

# Trace multiple system calls using the "-e trace=" option
strace -e trace=open,read ls /home

# To save the trace execution to a file using option "-o"
strace -o output.txt ls

# To execute strace on a running Linux process using option "-p" (process id)
ps -C firefox-bin
# PID TTY          TIME CMD
#  1725 ?        00:40:50 firefox-bin
sudo strace -p 1725 -o firefox_trace.txt

# To print timestamp for each trace output line using option "-t"
strace -t -e open ls /home

# To print relative time for system calls using option "-r"
strace -r ls

# To generate statistics report of system calls using option "-c"
strace -c ls /home