I am looking for a reliable way to find out the location in the filesystem of the program that runs when I enter a command.
ps -ef
gives me list of all currently running processes (-e
means every ; -f
means full list with relevant parameters).
So, to find the location of the uname
program, I tried
grep `uname -n &` `ps -ef`
I'm trying to catch uname -n
's process ID (PID) and forward it to grep
, which should return the line which contains that PID, so I could see which command is running at the moment.
I know there are commands like tee
, pipes... but I haven't succeeded in combining them to achieve my goal.
I suppose there is some shell function which returns stdout of called function, something like:
stdout(some__command)
so I could call:
grep stdout(uname -n &) stdout(ps -ef).
What am I missing here?
If all you want to know is the command location
If you want to know what directory the top level command is stored in you have a number of options:
The last option
locate
returns all files containinguname
not just the program that is run from the command prompt.strace - trace system calls and interrupts
You don't need the
pid
of commands called in order to find the names of various commands that are called by a function. Withstrace
all the command names are displayed directly.For your
uname -n
example the output is:For more information refer to
man strace
:Above is just the beginning of manpage for
strace