strace

Trace the system calls a program makes

About

strace records the system calls and signals a program makes as it runs, showing each request and its result. Reach for it when a command fails with a confusing message and you need to see which file or socket it actually touched. It can also attach to a process that is already running.

Install it

pkg install strace

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

strace ls /sdcard Run a command and print every system call it makes. You see exactly which files it opens.
strace -p 4321 Attach to a process already running and follow its calls. No restart needed.
strace -f Follow child processes created by the target. Matters for programs that spawn helpers.
strace -e trace=openat Show only the calls that open files. Cuts the noise down to the part you care about.
strace -c ls Summarise calls by count and time instead of printing each one. A quick performance overview.
strace -o calls.txt ls Write the trace to a file. A long or fast run can be read afterwards.

Worked example

Run strace -e trace=openat ls /sdcard and this is what you should see.

termux
$ strace -e trace=openat ls /sdcard
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/sdcard", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sdcard/Download", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 4

Developed by

strace project .