How do you find the environment for a running process?


cat /proc/<pid>/environ

Even though /proc/<pid>/environ has a size of 0, running a cat will still return the environment for this process. This file is just a kind of link to the actual location where the enviroment for this process is stored.

The ouput of the command above is not very readable since all strings are separated by NUL and not newlines. To convert them to newlines, you can use:

strings -f /proc/<pid>/environ


(cat /proc/<PID>/environ; echo) | tr "00" "n"


tr '' 'n' < /proc/<pid>/environ


xargs --null --max-args=1 echo < /proc/<pid>/environ


cat /proc/<pid>/environ | perl -pne '$a=chr(0);s/$a/n/g'

Note: you can get the pids of a process by using 
$ pidof httpd

This return a space separated list of the PIDs of all httpd processes.

Mac OS X

ps -p <pid> -wwwE


ps eww <pid>


pargs -e <pid>


The only way is to attach gdb to the process and examine _environ.


On Windows, you can do this by using a tool such as ProcessExplorer to select a particular process and view the values of the environment variables.

You could also write a small .NET program using:

One thought on “How do you find the environment for a running process?

Leave a Reply

Your email address will not be published. Required fields are marked *