Linux
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
or(cat /proc/<PID>/environ; echo) | tr " 00" "n"
ortr ' ' 'n' < /proc/<pid>/environ
orxargs --null --max-args=1 echo < /proc/<pid>/environ
orcat /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 Xps -p <pid> -wwwE
AIXps eww <pid>
Solarispargs -e <pid>
HP-UX
The only way is to attach gdb to the process and examine _environ.
Windows
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:
System.Diagnostics.Process.GetProcessById(<pid>).StartInfo.EnvironmentVariables
I hadn’t thought of using containers but that’s a great idea. Thanks so much for sharing!