What does strace show when a file is opened (open/openat)?
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.
Also asked at RWB
- Why did you decide to change jobs / leave your current company?
- What is the key difference between TCP and UDP?
- What is the difference between git merge and git rebase? When should each approach be used?
- What is an inode in Linux?
- Which command is used to determine the route of a packet from your device to the target host?
Similar questions
- What will strace output when run on a binary?
- What are Linux system calls, and which ones do you know?
- Which standard file descriptors do you know?
- Does a closed file have an inode? What is the difference between an open and a closed file when it is deleted?
- What is an inode, what information does it contain, and what does it not contain? Where are inodes physically located?