strace in Linux: trace system calls
Updated November 1, 2026
strace shows every system call a program makes to the kernel: which files it opens, what it reads, and where it fails.
Syntax
strace command # or: strace -p PIDCommon cases
strace ls # every system call of the ls command
strace -p 1234 # attach to a running process
strace -e trace=openat ls # only file-open calls
strace -f ./app # follow child processes too
strace -c ls # a summary: which calls and how much timeSample output
$ strace -e trace=openat cat /etc/nosuchfile
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
...
openat(AT_FDCWD, "/etc/nosuchfile", O_RDONLY) = -1 ENOENT (No such file or directory)
cat: /etc/nosuchfile: No such file or directory
+++ exited with 1 +++How it works: the line between a program and the kernel
A program does almost nothing directly on its own: open a file, send a packet, allocate memory - these are all requests to the kernel, system calls.
stracesits on that line and prints each call with its arguments and result. That makes it priceless when a program 'silently does not work': you see which file it failed to find (ENOENT) or which socket it could not connect to. The cost is a heavy slowdown, so in production you use it narrowly. In our sandboxstrace commandworks: the program starts as strace's own child. Attaching to a foreign process withstrace -p PIDneeds the PTRACE privilege, and that is not there.
Common mistakes
strace writes to the error stream, not to standard output. strace -e trace=openat cat /etc/hostname > out.txt puts a single line into the file, the host name, and the whole trace stays on the screen. Save it with the -o file flag or with a 2>file redirect.
A filter on the call name misses the target easily. strace -e trace=open cat /etc/hostname produces an empty log with one line, +++ exited with 0 +++: today's glibc does not call open, it calls openat. The same run with -e trace=openat prints 32 lines. When a filter comes back empty, check the call name before you draw conclusions about the program.
Without -f you see only the process you started. strace -e trace=openat -o a.log bash -c "cat /etc/hostname" collects 34 calls and not one of them mentions /etc/hostname: that file is opened by cat, a child of the shell. With -f the log grows to 66 lines and openat(AT_FDCWD, "/etc/hostname", O_RDONLY) = 3 is there.
Used in
You need this in the lesson Diagnosing a failure. The theory is the chapter System diagnosis and methodology.
See also
Open files: lsof, The /proc filesystem, Viewing processes.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.