*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
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.

about author-img author

I have no idea what to write here :(

no comments

Leave me comment