I want to trace existing process and especially their parameters (like environment variables, cwd directory, stdout and so on). I can do it. However, I cannot get that information about short-lived processes). For example:
If I run:
sleep 120 &
# get info from /proc/`pgrep sleep`
and it is easy.
But, what if my process is immediately terminated or I don't know PID of process (but I expect that some process will be created).
Best Answer
One approach as an ordinary user is an
exec
wrapper, assuming the programs are run via aPATH
search. That is, your wrapper forprogram
must exist first in
PATH
, so you might havePATH=/some/wrapper/dir:$PATH
and then a wrapperprogram
named exactly for the realprogram
to be logged, and in the wrapperprogram
you replace your wrapper with the originalprogram
usingexec
. If the program is being run by fully qualified paths then it may be necessary to fiddle around with something likeLD_PRELOAD
or perhaps the application in question may give an option to change the path?As
root
tracing would be quite simple with something likesysdig
(various sysdig examples) as that can match the ephemeral process names you are interested in, and can incrementally drill down to what you are interested in, say the programls
run as some user:The rather verbose
log
file after anls
is run shows anexecve
entry that may give almost everything you need (the environment is truncated):Via the user guide and other documentation, the above can be made precise to only the
execve
call and the full environment shown via:Adjust
-p
to show what you want; you could also use a chisel to extract what you want from a live capture or a save file, etc.