opensnoop(8)
β¨ opensnoop(8) β System Manager's Manual β¨
Okay bestie, this is the manual page for opensnoop π¦ Let's get into it.
β¨ NAME β¨
opensnoop is a tool that traces the open() syscall, and it runs on Linux with eBPF/bcc π
π SYNOPSIS π
opensnoop [-h] [-T] [-U] [-x] [-p PID] [-t TID] [-u UID]
[-d DURATION] [-n NAME] [-e] [-f FLAG_FILTER] [-F]
[--cgroupmap MAPPATH] [--mntnsmap MAPPATH]
π DESCRIPTION π
okay so opensnoop traces the open() syscall and shows you which processes are trying to open which files π It's honestly so useful for finding where config and log files live, or for figuring out why an app keeps failing, especially on startup π
Under the hood it traces the kernel sys_open() function using dynamic tracing. Heads up, it'll need updating if that function ever changes π
It uses a Linux 4.4 feature (bpf_perf_event_output()). If you're on a kernel older than 4.4, check out the version under tools/old, which uses an older mechanism π
Since this uses BPF, only the root user can use this tool. No exceptions, periodt π
π§ REQUIREMENTS π§
You'll need CONFIG_BPF and bcc β¨
πΈ OPTIONS πΈ
-hβ Prints the usage message π«Ά-Tβ Adds a timestamp column β°-Uβ Shows the UID πͺͺ-xβ Only prints failed opens π-p PIDβ Traces only this process ID, filtered in-kernel π―-t TIDβ Traces only this thread ID, filtered in-kernel π§΅-u UIDβ Traces only this UID, filtered in-kernel π€-d DURATIONβ The total duration of the trace, in seconds β³-n nameβ Only prints processes whose name partially matchesnameπ-eβ Shows the extended fields π₯-f FLAGβ Filters onopen()flags, likeO_WRONLYπ-Fβ Shows the full path for a file that was opened with a relative path πΊοΈ--cgroupmap MAPPATHβ Traces only the cgroups in this BPF map, filtered in-kernel π--mntnsmap MAPPATHβ Traces only the mount namespaces in this BPF map, filtered in-kernel π¦
π EXAMPLES π
# Trace all open() syscalls
opensnoop
# Trace all open() syscalls, but only for 10 seconds
opensnoop -d 10
# Trace all open() syscalls and include timestamps
opensnoop -T
# Show the UID
opensnoop -U
# Trace only the open() syscalls that failed
opensnoop -x
# Trace PID 181 only
opensnoop -p 181
# Trace UID 1000 only
opensnoop -u 1000
# Trace all open() syscalls from processes whose name partially
# matches 'ed'
opensnoop -n ed
# Show the extended fields
opensnoop -e
# Only print calls for writing
opensnoop -f O_WRONLY -f O_RDWR
# Trace a set of cgroups only (see special_filtering.md from the
# bcc sources for more details)
opensnoop --cgroupmap /sys/fs/bpf/test01
π§Ύ FIELDS π§Ύ
TIME(s)β When the call happened, in seconds β±οΈUIDβ The User ID πͺͺPIDβ The Process ID πTIDβ The Thread ID π§΅COMMβ The process name π·οΈFDβ The file descriptor if it succeeded, or-1if it failed πERRβ The error number (check the system'serrno.h) πFLAGSβ The flags passed toopen(2), in octal π’PATHβ The path that was opened π£οΈ
π«§ OVERHEAD π«§
This traces the kernel open function and prints output for each event. The rate is generally expected to be low (< 1000/s), so the overhead is also expected to be negligible π₯°
If you have an app that's calling a high rate of open()s, test it and understand the overhead before you use this π
π SOURCE π
This comes from bcc π¦
https://github.com/iovisor/bcc
Also look in the bcc distribution for a companion _examples.txt file. It has example usage, output, and commentary for this tool π
π» OS π»
Linux π§
π§ STABILITY π§
Unstable, it's still in development π οΈ
π AUTHOR π
Brendan Gregg and Rocky Xing π«Ά
π SEE ALSO π
execsnoop(8), funccount(1) π
Bye bestie, that's the whole page π Shoutout to bcc for the source, the 2020-02-20 USER COMMANDS version, and the opensnoop(8) manual section π§β¨
π¦ where this page comes from
- alpine 3.24: bcc-doc 0.36.1-r1 Β· Apache-2.0
- nixpkgs unstable: bcc 0.37.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms