[dtrace-discuss] Re: How to get absolute path?

Ian ian.archer.am.i at gmail.com
Tue Jan 16 07:46:21 PST 2007


A little bit of process watching can really help deal with this problem.  What we want is a process 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 that are running before the dtrace session will not reveal their cwd until a chdir.  But my preliminary testing suggests it is sufficient as a reasonably accurate solution, especially when dtrace is run early in a user's session.
 
 
This message posted from opensolaris.org


More information about the dtrace-discuss mailing list