execsnoop-bpfcc: Trace exec() syscalls
execsnoop-bpfcc [-h] [-T] [-t] [-x] [--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP] [-u USER] [-q] [-n NAME] [-l LINE] [-U] [-C] [-M] [--max-args MAX_ARGS] [-P PPID]
What it does
Trace exec() syscalls. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/execsnoop-bpfcc; upstream and other distributions call it execsnoop). It loads an eBPF program, so it needs root.
Options you will use
-T, --time- include time column on output (HH:MM:SS)
-t, --timestamp- include timestamp on output
-x, --fails- include failed exec()s
--cgroupmap CGROUPMAP- trace cgroups in this BPF map only
--mntnsmap MNTNSMAP- trace mount namespaces in this BPF map only
-u, --uid USER- trace this UID only
-q, --quote- Add quotemarks (") around arguments.
-n, --name NAME- only print commands matching this name (regex), any arg
-l, --line LINE- only print commands where arg contains this line (regex)
-U, --print-uid- print UID column
-C, --print-cpu- print CPU column
-M, --print-pcomm- print parent command
--max-args MAX_ARGS- maximum number of arguments parsed and displayed, defaults to 20
-P, --ppid PPID- trace this parent PID only
Examples
$ sudo execsnoop-bpfcctrace all exec() syscalls
$ sudo execsnoop-bpfcc -xinclude failed exec()s
$ sudo execsnoop-bpfcc -Tinclude time (HH:MM:SS)
$ sudo execsnoop-bpfcc -P 181only trace new processes whose parent PID is 181
$ sudo execsnoop-bpfcc -Uinclude UID
$ sudo execsnoop-bpfcc -Cinclude CPU
$ sudo execsnoop-bpfcc -Minclude PCOMM
$ sudo execsnoop-bpfcc -u 1000only trace UID 1000
Gotchas
- Catches processes that live too short for top or pidstat: PPID leads to the parent that keeps starting them.
- As a normal user it fails with "could not open bpf map: ..., error: Operation not permitted" (unprivileged BPF is off on Ubuntu).
Taught in
On the blog
Try execsnoop-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.