Attach to a running process

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

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

tool
strace13 commands
tags
stracelinuxdebug

More strace commands

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

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

  • strace -c -e trace=all python3 app.py

    Print a summary table with the count and time of each syscall

  • strace -f -e trace=process nginx -t

    Trace process syscalls like fork and exec in all child processes (-f)

  • strace -tt -T curl https://example.com 2>&1 | head -40

    -tt adds the wall-clock time, -T shows how long each call took

  • strace -e trace=openat -e trace=file myapp 2>&1 | grep 'ENOENT'

    Find files that the process tries to open but cannot find

all 13 strace commands