execsnoop(8) | System Manager's Manual | execsnoop(8) |
execsnoop - trace process exec() with arguments. Uses Linux ftrace.
execsnoop [-hrt] [-a argc] [-d secs] [name]
execsnoop traces process execution, showing PID, PPID, and argument details if possible.
This traces exec() from the fork()->exec() sequence, which means it won't catch new processes that only fork(). With the -r option, it will also catch processes that re-exec. It makes a best-effort attempt to retrieve the program arguments and PPID; if these are unavailable, 0 and "[?]" are printed respectively. There is also a limit to the number of arguments printed (by default, 8), which can be increased using -a.
This implementation is designed to work on older kernel versions, and without kernel debuginfo. It works by dynamic tracing an execve kernel function to read the arguments from the %si register. The stub_execve() function is tried first, and then the do_execve() function. The sched:sched_process_fork tracepoint, is used for the PPID. Tracing registers and kernel functions is an unstable technique, and this tool may not work for some kernels or platforms.
This program is a workaround that should be improved in the future when other kernel capabilities are made available. If you need a more reliable tool now, then consider other tracing alternatives (eg, SystemTap). This tool is really a proof of concept to see what ftrace can currently do.
Since this uses ftrace, only the root user can use this tool.
FTRACE and KPROBE CONFIG, sched:sched_process_fork tracepoint, and either the stub_execve() or do_execve() kernel function. You may already have these on recent kernels. And awk.
This reads and processes exec() events in user space as they occur. Since the rate of exec() is expected to be low (< 500/s), the overhead is expected to be small or negligible.
This is from the perf-tools collection.
Also look under the examples directory for a text file containing example usage, output, and commentary for this tool.
Linux
Unstable - in development.
Brendan Gregg
2014-07-07 | USER COMMANDS |