*nix processes and env vars

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

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.

About “Mujtaba Hussain”

I have no idea what to write here :(