The strace command failed because the target file for tracing open() and openat() syscalls doesn’t exist, preventing strace from attaching to or observing the file operations.

This usually happens when the path you provide to strace as the file to trace is incorrect, or the file was deleted before strace could start monitoring it. The core issue is that strace needs a valid file descriptor or path to a file to observe its system calls. When that file is gone, strace can’t establish the link it needs.

Here are the most common reasons this happens and how to fix them:

  1. Typo in the Filename or Path: This is the most frequent culprit. A single incorrect character in the filename or directory path will cause open() or openat() to fail with ENOENT (No such file or directory).

    • Diagnosis: Double-check the exact spelling and case of the filename and its full path. Use ls -l /path/to/your/file to verify its existence and exact name.
    • Fix: Correct the path in your strace command. For example, if you intended to trace /var/log/syslog.log but typed /var/log/syslog.logx, change it to the correct path.
    • Why it works: strace relies on the operating system’s file system to locate the file. A correct path allows the kernel to find and open the file, enabling strace to attach and trace subsequent open() calls.
  2. File Was Deleted Before strace Started: You might have specified a valid path, but the file was removed by another process or user between the time you typed the command and when strace attempted to open it.

    • Diagnosis: Immediately after seeing the error, try ls -l /path/to/your/file again. If it’s gone, this is the issue.
    • Fix: If possible, recreate the file or ensure the process that’s supposed to create it is running and hasn’t encountered its own error. If you are tracing a file that should be created by another command, run strace before running that command. For example: strace -o trace.log -e trace=open,openat your_command_that_creates_file.
    • Why it works: By starting strace before the file is expected to exist (or before the command that creates it runs), you ensure that strace is ready to observe the open() or openat() call that will create the file, rather than looking for a file that already should exist.
  3. Incorrect Working Directory: If you’re using a relative path, strace will look for the file relative to its own current working directory, which might not be what you expect.

    • Diagnosis: Run pwd to see your current directory. Then, check if the relative path you provided makes sense from that directory. For example, if you are in /home/user and try to trace logs/app.log, but the file is actually at /opt/app/logs/app.log, the relative path is wrong.
    • Fix: Either use an absolute path (e.g., /opt/app/logs/app.log) or cd into the correct directory before running strace. So, cd /opt/app/logs/ and then strace -o trace.log -e trace=open,openat app.log.
    • Why it works: Relative paths are resolved against the current working directory of the process executing the command. By ensuring strace is run from the correct directory or by providing an absolute path, you guarantee the file system lookup starts from the right place.
  4. Permissions Issues (Less Common for ENOENT): While ENOENT is typically "file not found," sometimes permission issues on parent directories can manifest oddly. If a user doesn’t have execute permission on a directory in the path, they can’t traverse into it, and the kernel might report the file as not found.

    • Diagnosis: Check permissions on all directories leading up to the file. Use ls -ld /path, ls -ld /path/to, etc., for each component of the path. Ensure your user has x (execute) permission on all of them.
    • Fix: Grant execute permission on the necessary directories. For example, chmod +x /path/to/directory.
    • Why it works: The x permission on a directory allows a process to enter that directory and access its contents (including looking up files by name). Without it, the path traversal fails, and the file is effectively invisible.
  5. Special File System or Mount Issues: If the file resides on a network mount, a special file system (like /proc or /sys), or a symlink, issues with the mount point or the target of the symlink can cause open() to fail with ENOENT.

    • Diagnosis: Verify the mount point is active and healthy using mount | grep your_mount_point. If it’s a symlink, check its target with ls -l /path/to/symlink.
    • Fix: Remount the file system if necessary, or ensure the target of the symlink exists and is accessible. For example, if /mnt/data is a failed NFS mount, you might need to sudo mount -a or sudo mount -t nfs your.server:/share /mnt/data. If a symlink is broken, fix it: ln -s /new/target /path/to/symlink.
    • Why it works: strace interacts with the kernel’s file system layer. If that layer encounters an issue with a mount point or a broken symbolic link, the underlying open() call will fail, and strace will report the failure.
  6. SELinux or AppArmor Restrictions: Security modules like SELinux or AppArmor can prevent processes (including strace or the process being traced) from accessing files, sometimes resulting in ENOENT if the denial is configured that way.

    • Diagnosis: Check system logs for SELinux or AppArmor denials. For SELinux, this is often in /var/log/audit/audit.log (look for AVC messages). For AppArmor, check /var/log/syslog or dmesg.
    • Fix: Adjust the SELinux/AppArmor policy to allow the operation. This might involve chcon for SELinux file contexts or aa-complain/aa-enforce and policy editing for AppArmor. For example, sudo setenforce 0 temporarily disables SELinux to test if it’s the cause. If it is, you’ll need a more permanent policy change.
    • Why it works: These security systems act as an additional layer of checks before the kernel allows a system call to proceed. If a policy explicitly denies access to a file, the kernel might return ENOENT to the calling process as if the file wasn’t there, rather than revealing that access was denied.

After fixing the "file not found" error, you’ll likely encounter the next logical step in tracing: strace will successfully attach, and you’ll see the open() or openat() call, followed by its return value (often a file descriptor, or -1 with errno if it failed for another reason).

Want structured learning?

Take the full Strace course →