Print a stack trace for each syscall

Print the user stack on each openat to see which code opens the file; needs debug symbols

strace -k -e trace=openat -f -p <pid>

tool
strace13 commands
tags
stracedebugtroubleshootingdisk

More strace commands

  • strace -f -e inject=openat:error=ENOENT:when=3 -p <pid>

    Make the 3rd openat fail with ENOENT to test error handling; chaos testing without changing code

  • strace -f -e signal=all -e trace=none -p <pid>

    Show only signals like SIGTERM and SIGCHLD and skip syscalls, to find out who killed the process; for library calls use ltrace

  • strace -o trace.log ls /tmp

    Run a command under strace and save the output to a file

  • strace -p $(pgrep nginx | head -1) -o /tmp/nginx.trace

    Trace the syscalls of a process that is already running, by PID

  • strace -e trace=openat,read,write curl https://example.com

    Show only openat, read and write calls and hide the rest

all 13 strace commands