A program fails with a vague message, or no message at all, and the logs say nothing. Underneath, every program that opens a file, connects to a server or reads a setting has to ask the kernel to do it, through a system call, and the kernel answers with a result or an error code. strace prints those requests and answers as they happen. The examples below were all run with strace 6.8 on Linux, and the output shown is what it printed, trimmed only where noted.
What strace shows
Every request, every answer
The strace manual describes the basic use: it runs the specified command until it exits, and it intercepts and records the system calls made by a process and the signals it receives. For each call it prints the name, the arguments and the return value, to standard error or to a file given with -o.
The value of that is the return code. Applications often turn a precise kernel error into a generic message, or swallow it. strace shows the precise one.
The missing file
The most common use is finding which file a program could not open. cat nofile.conf with only openat calls traced:
$ strace -f -e trace=openat -o t1.txt cat nofile.conf
$ grep ENOENT t1.txt
7038 openat(AT_FDCWD, "nofile.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
-1 ENOENT is the kernel saying no such file. For cat the message would have said the same thing; for a server that reads a dozen configuration paths in a fixed order and reports only “configuration error”, this line names the exact path it tried.
Permission problems
The same pattern finds permission failures. A file with mode 000, read as the unprivileged nobody user:
openat(AT_FDCWD, "/tmp/st6MOB/secret", O_RDONLY) = -1 EACCES (Permission denied)
EACCES against a specific path, with the user it ran as known, usually settles a “works for root, fails for the service” problem in one look.

A worked case: which config file did it read?
The silent fallback
Missing files are not always errors. Many programs search a list of places for a configuration file and use the first one they find, quietly. A small test program looked for its settings in ~/.toolrc, then ./etc/toolrc, then /etc/toolrc, and printed the timeout it ended up with. With a home directory containing .toolrc, it printed timeout=60. Run with a home directory that did not exist, it printed timeout=5, from a different file, with no warning.
From the outside, that looks like a setting that changed by itself. strace shows the search:
openat(AT_FDCWD, "/tmp/st2k8XM/nohome/.toolrc", O_RDONLY|O_CLOEXEC) = -1 ENOENT
openat(AT_FDCWD, "./etc/toolrc", O_RDONLY|O_CLOEXEC) = 3
The first attempt failed, the second succeeded, and the = 3 is the file descriptor the kernel handed back. The program read ./etc/toolrc. The same two lines are how to settle a job that works from an interactive shell but not under cron: cron jobs often run with a different HOME and working directory, and a trace shows the difference in the paths themselves.
Shorter, more focused output
Two more options keep traces readable. -s limits how many characters of each string argument are printed; with -s 8, a write of a 22-byte line showed as write(1, "a long l"..., 22). And -Z prints only calls that failed. Combined with -e trace=%file on python3 -c "1", it cut the output to 52 lines, every one of them a path Python looked for and did not find, which is exactly the list to read when hunting a missing module or library.
Filtering the output
-e trace=
Untrimmed, strace output is long; even a short program makes hundreds of calls. The -e trace= option keeps only the ones asked for. Besides individual names, strace accepts classes; %file covers every call that takes a file name. Running python3 -c "import json" with -e trace=%file logged 247 calls, 59 of them failing with ENOENT.
Those 59 failures were not errors. Python searches several directories for every module it imports, and each place it looks and does not find the file shows up as an ENOENT. That is the most important habit in reading strace output: a failed call is a fact, not necessarily a fault. The failure that matters is usually the last one before the program gives up.
-o and grep
Writing the trace to a file with -o and searching it afterward is easier than reading it live. With -f, each line is prefixed with the process ID, which matters for the next section.

Following child processes
-f
Many programs start others: a shell script runs commands, a server forks workers. Without -f, strace traces only the first process. The manual describes -f as tracing child processes as they are created by traced processes through fork, vfork and clone.
In the earlier missing-file example, the 7038 at the start of the line is the process ID that -f adds. In a trace of a script that runs several commands, those numbers are how the lines are told apart.
Attaching to a running process
-p
A process that is already running, and misbehaving, can be traced without restarting it. The manual says -p attaches to the process with that ID and begins tracing, and that the trace can be ended at any time with Ctrl-C, at which point strace will respond by detaching itself and the process carries on.
Attached to a sleep, strace reported:
strace: Process 7102 attached
restart_syscall(<... resuming interrupted read ...> <detached ...>
strace: Process 7102 detached
The process was in the middle of a sleep, so the only call in progress was the kernel resuming it. For a hung server, that one line is often the answer by itself: a process stuck in read on a socket is waiting on the network, and one stuck in futex is waiting on a lock. Attaching to another user’s process requires root, and some systems restrict attaching further.

Timing and counting
-T: how long each call took
-T shows the time spent inside each system call, and -tt adds a wall-clock timestamp with microseconds. On sleep 0.3:
23:32:29.895262 clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=300000000}, ...) = 0 <0.300229>
The <0.300229> at the end is the time the call took: 0.3 seconds, as asked. On a slow program, sorting by that number points at the call that is waiting.
-c: a summary instead of a trace
The manual describes -c as counting time, calls and errors for each system call and reporting a summary on program exit, suppressing the normal output. ls -la /usr/lib produced, in part:
% time seconds usecs/call calls errors syscall
48.25 0.001866 26 71 statx
16.11 0.000623 8 71 71 lgetxattr
14.95 0.000578 8 69 listxattr
1.16 0.000045 11 4 4 connect
That is a portrait of ls -la: one statx per entry to read its details, plus extended-attribute checks that fail on this filesystem, 71 times out of 71. The manual notes that the summary shows system time, CPU time spent in the kernel, which is independent of wall-clock time.
The connect calls nobody asked for
The summary also showed four failed connect calls from a program that only lists files. Tracing just those:
connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT
ls was trying to look up user and group names through the name service cache daemon, which was not running, and then falling back to reading the files directly. Harmless here; on a system where that lookup went to a slow network directory, the same four calls would explain why ls -l hangs while ls does not.
The cost of watching
strace is not free. Every system call the traced program makes stops, gets reported to strace, and resumes. A Python loop that called stat 20,000 times ran in 0.031 seconds on its own. Under strace writing to /dev/null, the same loop took 1.075 seconds, about 35 times longer; with -c, which skips printing each call, it still took 0.989 seconds. The slowdown is in the stopping, not the printing.
For a short diagnostic run that does not matter. For a production process under load, it does: attaching strace to a busy server can slow it enough to change the problem being investigated, or to cause a new one. Narrowing helps somewhat: tracing only openat, which the loop never called, brought a repeat run down from 1.20 to 0.66 seconds, still about 20 times the untraced time. Tracing for seconds rather than minutes, and at a quiet moment, is the safer habit.
Network and file descriptors
Seeing which address a program dials
-e trace=connect shows every outgoing connection with its address. A Python script connecting to port 9 on localhost, where nothing was listening:
connect(3, {sa_family=AF_INET, sin_port=htons(9), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS
py: [Errno 111] Connection refused
The address and port appear in plain form, which answers the frequent question of which server, which port, or which of several configured hosts a program is actually trying. (EINPROGRESS is normal for a non-blocking connect; the refusal arrived a moment later.)
-y: file names instead of numbers
System calls refer to open files by descriptor number, which says little on its own. -y decodes them; the manual describes it as decoding information associated with file descriptors, with paths as the default set. A read became:
read(3</tmp/st6MOB/present.txt>, "hello\n", 131072) = 6
Descriptor 3 is that file. The same option on a busy process is a quick way to see what it has open, which pairs well with the descriptor limits covered in the earlier post on too many open files.
Sources
- strace(1), Linux manual page (man7.org): https://man7.org/linux/man-pages/man1/strace.1.html
