[dtrace-discuss] Re: How to get absolute path?
Casper.Dik at Sun.COM
Casper.Dik at Sun.COM
Tue Jan 16 08:32:15 PST 2007
>A little bit of process watching can really help deal with this problem. What we want is a proces
s table which maps a pid to the current directory of that process (the 'cwd' environment variable,
at least on Mac OS X currently, only reveals the enclosing directory and not its absolute path, so
we need to do the legwork ourselves).
>
>If we look for *forks and execve, we give the new process the cwd of the parent (assuming we have
the cwd of the parent ;). We can also trap chdir|fchdir to monitor updates to the cwd of a process
. We can then prepend any relative path of a file access with the cwd of the accessing process.
>
>I assume that there are cases in which this breaks down; a more obvious one being when processes t
hat are running before the dtrace session will not reveal their cwd until a chdir. But my prelimin
ary testing suggests it is sufficient as a reasonably accurate solution, especially when dtrace is
run early in a user's session.
Solaris does maintain all this information directly of the u. structure, so there's no need
to do all that bookkeeping.
This makes me wonder if a dtrace implementation should not simply offer this as an abstraction.
Casper
More information about the dtrace-discuss
mailing list