NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle1 view

What does strace show when a file is opened (open/openat)?

Practice

Asked at

AI answer

strace shows the system call used to open a file, the arguments passed to it, and the result. For example:

openat(AT_FDCWD, "/etc/hosts", O_RDONLY) = 3

This means the file was opened relative to the process's current working directory (the special value AT_FDCWD) in read-only mode, and the kernel returned file descriptor 3. On failure, the result will be negative and include the reason, for example:

openat(AT_FDCWD, "/no/such/file", O_RDONLY) = -1 ENOENT (No such file or directory)

On modern Linux systems, openat is commonly used; older or other code may call open. To filter the output, you can use strace -e trace=open,openat <command>. The open call itself opens the file and returns a descriptor—reading its contents will appear in separate calls, such as read.