execsnoop(8)

πŸ“¦
version 0.36.1 Β· 2 versions
, in alpine 3.24, nixpkgs unstable, opensuse-leap 16.0

✨ execsnoop(8) ✨


πŸ’– NAME πŸ’–

execsnoop is a tracer for new processes, using exec() syscalls. It runs on Linux eBPF/bcc. ✨

🧚 SYNOPSIS 🧚

execsnoop [-h] [-T] [-t] [-x] [--cgroupmap CGROUPMAP] [--mntnsmap MAPPATH] [-u USER] [-q] [-n NAME] [-l LINE] [-U] [--max-args MAX_ARGS]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so execsnoop traces new processes and shows you the filename being executed plus the argument list. iykyk 🫢

It works by tracing the execve() system call, which is the most common exec() variant. This catches new processes that follow the fork->exec sequence, and processes that re-exec() themselves. Some apps will fork() without exec()ing, like worker processes, and those won't show up in the execsnoop output πŸ™ˆ

It works by tracing the kernel sys_execve() function using dynamic tracing, so it'll need updating to match any changes to that function. bestie, keep that in mind πŸ’€

Since this uses BPF, only the root user can use this tool. No exceptions, no vibes-based workarounds πŸ”₯

πŸŽ€ REQUIREMENTS πŸŽ€

You'll need CONFIG_BPF and bcc. ✨

πŸ’… OPTIONS πŸ’…

  • -h β€” Prints the usage message. Your lifeline when you forget the flags πŸ“
  • -T β€” Adds a time column in HH:MM:SS format ⏰
  • -U β€” Adds the UID column πŸ†”
  • -t β€” Adds a timestamp column ✨
  • -u USER β€” Filters by UID or username πŸ‘‘
  • -x β€” Also includes failed exec()s, the ones that didn't go through πŸ’€
  • -q β€” Wraps arguments in "quotemarks" and escapes any quotemarks inside them with a backslash. This is the move for tracing empty arguments or arguments with whitespace in them πŸŽ€
  • -n NAME β€” Only prints command lines matching this name, using a regex πŸ”
  • -l LINE β€” Only prints commands where an argument contains this line, using a regex 🧡
  • --max-args MAXARGS β€” The max number of arguments parsed and displayed. Defaults to 20 🌸
  • --cgroupmap MAPPATH β€” Traces only the cgroups in this BPF map. It's filtered in-kernel, so it's lowkey efficient 🌈
  • --mntnsmap MAPPATH β€” Traces only the mount namespaces in this BPF map. Also filtered in-kernel 🧚
  • -P PPID β€” Traces only this parent PID πŸ¦‹

🌈 EXAMPLES 🌈

Here are the vibes, bestie πŸ’–

  • Trace all exec() syscalls: # execsnoop
  • Trace all exec() syscalls and include timestamps: # execsnoop -t
  • Display the process UID: # execsnoop -U
  • Trace only UID 1000: # execsnoop -u 1000
  • Trace only processes launched by root and display the UID column: # execsnoop -Uu root
  • Include failed exec()s: # execsnoop -x
  • Put quotemarks around arguments: # execsnoop -q
  • Only trace exec()s where the filename contains "mount": # execsnoop -n mount
  • Only trace exec()s where an argument's line contains "testpkg": # execsnoop -l testpkg
  • Trace a set of cgroups only (check special_filtering.md from the bcc sources for more details): # execsnoop --cgroupmap /sys/fs/bpf/test01

πŸ“‹ FIELDS πŸ“‹

  • TIME β€” When the exec() returned, in HH:MM:SS format ⏰
  • TIME(s) β€” When the exec() returned, in seconds ⏳
  • UID β€” The user ID πŸ†”
  • PCOMM β€” The parent process or command name πŸ‘―
  • PID β€” The process ID πŸͺͺ
  • PPID β€” The parent process ID πŸ‘‘
  • RET β€” The return value of exec(). 0 means success! Failures only show up when you use the -x option πŸ’…
  • ARGS β€” The filename for the exec(), followed by up to 19 arguments. An ellipsis ... shows up if the argument list is known to be truncated 🫣

πŸ”₯ OVERHEAD πŸ”₯

This traces the kernel execve function and prints output for every event. The rate is usually expected to be low (< 1000/s), so the overhead should be negligible. But if your app is calling exec() at a high rate, test it and understand the overhead before you use this tool. Don't be the girl who tanks prod πŸ’€

🌸 SOURCE 🌸

This is from bcc, found at:

https://github.com/iovisor/bcc

Also check the bcc distribution for a companion _examples.txt file. It has example usage, output, and commentary for this tool πŸ“š

πŸ“ OS πŸ“

Linux 🐧

🫧 STABILITY 🫧

Unstable, still in development 🚧

πŸ’œ AUTHOR πŸ’œ

Brendan Gregg, Rocky Xing πŸ‘©β€πŸ’»

πŸ¦‹ SEE ALSO πŸ¦‹

opensnoop(1) πŸ‘€


Bye bestie 🫢 This page is from USER COMMANDS, dated 2020-02-20, and it's all about execsnoop(8) πŸ’–βœ¨