Recently a colleague of mine showed me how to find out what environment variables a process is using at the time its running. This works on Linux but not on OS X.

Find out the PID for the process you want to inspect

[@riyadh:~] $ ps -ef | grep mysql
mysql 1142 1 0 Jul06 ? 00:00:24 /usr/sbin/mysqld

Then its a simple step of catting the environ section of proc for that PID which in this case is 1142

[@riyadh:~] $ sudo cat /proc/1142/environ
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
TERM=linuxHOME=/etc/mysqlRUNLEVEL=2PREVLEVEL=NUPSTART_EVENTS=runlevel
UPSTART_JOB=mysqlUPSTART_INSTANCE=

On OS X, you can get information by using:

[@riyadh:~] $ ps -Eww $PID

Be warned, this gives you a lot more than just what environment variables that process is using.

The following two tabs change content below.
Software Developer at realestate.com.au. Ardent rock climber, long distance runner and cricketer. Passionate about geometry, algorithms, persian poetry and test cricket. Loves to climb at the Sundeck Valley in Grampians, Australia.

Latest posts by Mujtaba Hussain (see all)