Back to the command reference

strace

ProcessesAdvanced In real Linux

Trace system calls of a program

Name: strace = system call trace

This command needs a real Linux system; you can practise it in real Linux mode.

Description

strace runs a program (or attaches to a running one) and logs every system call with its arguments and result: which files it opens, what it reads and writes, what fails. A powerful debugging tool.

Syntax

strace [OPTION]... COMMAND

Common options

-p PIDAttach to a running process
-fFollow child processes and threads too
-e EXPRTrace only some calls, e.g. -e trace=open
-cCount calls and time per system call instead of listing them
-t / -ttPrefix each line with the time (-tt with microseconds)
-TShow the time spent in each call
-s STRSIZEHow much of each string to show (32 by default)
-o FILEWrite output to a file

Examples

  • $ strace ls

    See the system calls ls makes

    Explain
  • $ strace -e trace=openat cat notes.txt

    See which files a program opens

    Explain

Related