Skip to content

strace

18 commands

Traces the system calls and signals of a process — see which files it opens, what it sends and why it fails.

  • tracing
  • system calls
  • debugging

Install strace

sudo apt install strace

Tracing5

strace <command>

Runs a program and prints every system call with arguments and return values to stderr.

Link
strace -p <pid>

Attaches to a running process.

Link
strace -f <command>

Follows child processes and threads.

Link
strace -o <file> <command>

Writes the trace to a file.

Link
strace -ff -o <prefix> <command>

One output file per process (trace.<pid>).

Link

Filtering6

strace -e trace=<calls> <command>

Only the listed system calls.

Link
strace -e trace=%file <command>

Every call that takes a file name — shows config files and libraries it looks for.

Link
strace -e trace=%network <command>

Network calls: socket, connect, sendto and friends.

Link
strace -e trace=%process <command>

Process lifecycle: fork, clone, execve, exit.

Link
strace -e trace=execve -f <command>

Every program a script launches.

Link
strace -e status=failed <command>

Only calls that failed (strace 5.2+) — quickly shows missing files and permission errors.

Link

Detail and timing5

strace -s <n> <command>

Shows up to n characters of string arguments (default 32).

Link
strace -tt -T <command>

Microsecond timestamps and time spent in each call.

Link
strace -c <command>

A summary table of call counts, errors and time instead of a full trace.

Link
strace -y <command>

Prints the path behind each file descriptor.

Link
strace -k <command>

Prints a stack trace for each call.

Link

Library calls2

ltrace <command>

Traces calls into shared libraries — strcmp calls often reveal hard-coded passwords.

Link
ltrace -e <function> <command>

Traces only the named library function.

Link