Skip to content
systemcoding.dev
Debugging

Trace whole syscall classes with %file and %network

Trace a whole group of syscalls with strace 6.x by naming a class such as -e trace=%file or %network instead of listing every call.

1 min read
Summarize in AI

Listing open,openat,stat,access by hand always misses one. strace has named classes for this, written with a leading %, and they cover every call in the group on the running architecture. -e trace=%file takes the calls that name a file, and %network takes the socket family. The strace manual lists the classes, and they need strace 5.3 or newer, with the % spelling.

Shell
strace -f -e trace=%file,%network -o app.trace curl -s http://127.0.0.1:8080/ >/dev/null
Text
execve("/usr/bin/curl", ["curl", "-s", "http://127.0.0.1:8080/"], 0x7ffc8e0d5a58 /* 31 vars */) = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 5
connect(5, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("127.0.0.1")}, 16) = 0

The two classes are joined with a comma in a single -e. The call list is the same one you would have had to maintain by hand, including the *at variants and execve, which counts as a file call because it names a path. Other classes include %process, %signal, %memory and %desc.

Class names are matched per architecture, so a 32-bit process under a 64-bit kernel still gets its own syscall names. The classes tell you which calls to watch, not whether the program is behaving, so read the return values as well. PIDs, addresses and the environment count in the lines above will differ.

Share

More snippets

Systems Programming

Get the page size with sysconf(_SC_PAGESIZE)

Read the memory page size at run time with sysconf(_SC_PAGESIZE) instead of hard-coding 4096, which is wrong on arm64 kernels built with 16K or 64K pages.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.