For a given process ID, what is the best/most direct way to determine the environment variables (e.g. PATH)? Must be able to query for any arbitrary environment variable. PATH is just the first example.
'lsof -a -p $PID -d cwd -F' gets some of it.
But, I don't see a way to get the PATH for the given PID, using lsof.
'ps -Ep $PID' gets some of it.
But, again, 'not comprehensive. It appears to give back only a portion of the 'environment' for the process.
On a number of other Linux/UNIX variants, you can look at '/proc//environ'. But, OS X apparently does not use that mechanism.
You should get this information (and a little extra) with ps -Eww $PID
The reason you were only seeing part of the environment is that ps will trim the output to fit your window (if going to stdout). Adding "ww" to the flags tells ps not to be concerned with window size.