Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Debugging Linux system calls with strace

Using strace to debug system call issues in Linux reveals what a program asks the kernel to do and how each request succeeds or fails. It captures system call arguments, return values and error codes, making hidden problems visible without changing application source code.

The tool is particularly useful when a service starts but cannot read configuration, connects to the wrong endpoint, hangs during startup or behaves differently on another host. It complements log files by showing the exact sequence of kernel operations behind an error.

Australian managed-service and hosting teams commonly support RHEL estates from Sydney and Melbourne. They may also need to reconcile AEST and ACST daylight-saving changes, follow Australian Cyber Security Centre incident-response guidance and meet Privacy Act obligations when diagnostic output contains customer data.

Seeing what a process really does

A strace line contains the system call, its arguments and the kernel response. For example, openat(AT_FDCWD, "/etc/myapp.conf", O_RDONLY) = -1 ENOENT shows that a configuration file was not found. A successful call returns a file descriptor, while a negative value identifies the relevant errno.

Start with a focused trace rather than capturing everything. Run sudo strace -f -tt -T -o /tmp/myapp.strace /usr/local/bin/myapp to follow child processes, add wall-clock timestamps, report call durations and save the output. Before investigating a live host, check that tracing will not conflict with endpoint controls; broader endpoint security guidance can inform that review.

Installing strace and defining scope

On RHEL, Fedora and newer CentOS releases, install the tracer with sudo dnf install -y strace. CentOS 7 and other older yum-based systems use sudo yum install -y strace. Confirm the installed version with strace -V, since newer releases support additional filtering and formatting options.

Use -f to follow processes created with fork or clone, -p PID to attach to an existing process and -e trace=openat,connect to restrict the capture to selected calls. The -s option limits printed string length, while -o writes to a file instead of the terminal. If attaching is blocked, check the kernel’s ptrace_scope setting and whether the tracer is running in the correct PID namespace.

Tracing missing files and libraries

Configuration problems often become clear from file-related calls. Capture calls such as open, openat, stat and access, then compare the requested paths with the service account’s working directory. A relative path that works in an administrator’s shell may fail under systemd because the service uses a different working directory.

Library-loading failures produce a similarly useful pattern. Look for ENOENT against shared objects and linker configuration files, followed by an execve failure reporting a missing library. Inspect the process with readlink /proc/PID/exe, cat /proc/PID/maps and lsof -p PID. These checks reveal whether the binary, loader or dependency files differ from the installation expected by the service.

Following network and time behaviour

Filter network activity with strace -e trace=socket,connect,sendto,recvfrom,sendmsg,recvmsg. A refused connection returns ECONNREFUSED, an unreachable destination may produce EHOSTUNREACH, and a failed TLS or HTTP request can occur after the TCP connection succeeds. The trace can therefore distinguish DNS failure, routing trouble and an application-level rejection.

Name resolution needs separate interpretation. The resolver may appear as a connection to a DNS server, while the actual DNS message is hidden inside sendto and recvfrom. Compare /etc/resolv.conf with getent hosts hostname and a direct lookup such as dig hostname. Proxy variables such as HTTP_PROXY, HTTPS_PROXY and NO_PROXY can also redirect traffic unexpectedly in Australian corporate networks.

For distributed services, use strace -ttt when writing the trace so timestamps use Unix epoch time. This avoids ambiguity when comparing a Sydney host with a colleague’s logs or when daylight-saving changes make wall-clock values appear inconsistent.

Diagnosing errors hangs and blocked calls

A process that appears stuck often waits in futex, poll, select, epoll_wait or nanosleep. The -T option prints how long each call took, making a slow dependency easier to identify. A call that returns immediately while the application consumes CPU may point away from blocking I/O and towards a busy loop, making perf or top useful complementary tools.

Unexpected EACCES indicates a permission or policy problem, while EPERM may reflect a seccomp profile or another security control. Check file ownership, capabilities and relevant audit records before changing policy. If strace cannot attach at all, inspect ptrace_scope; running the tracer with sudo usually resolves ordinary user restrictions but not every container or hardened configuration.

Historical process context can come from acct and lastcomm. The system accounting guide explains how to configure those tools when tracing alone cannot reconstruct which account started an activity.

Running a safe focused trace

Tracing a production service can slow it down and may expose credentials, tokens or personal data passed as system call arguments. Truncation with -s reduces output size but does not guarantee redaction. Prefer a staging reproduction with equivalent SELinux policies, mounts, environment variables and network paths. If a live trace is unavoidable, use narrow filters, a short capture window and a protected output file.

Keep the diagnostic sequence controlled: record the application log, run the tracer with relevant filters, identify the first unexpected return value and compare it with the expected startup or request path. Avoid disabling firewall rules, seccomp profiles or mandatory access controls merely to make the trace succeed, because that can conceal the actual fault.

The next concrete step is to run one focused staging reproduction with strace -ttt -T and file the resulting trace beside the matching application log.