When creating init scripts or trying to debug services on Linux it can be handy
to know what the environment variables are for a running process. It turns out
that you can retrieve these variables from /proc
(along with lots of
other rather useful information). The environment variables are located in
/proc/$PID/environ
where $PID
is the ID of the process we are
interested in.
cat
can be used to print out the environment variables, but the entries
are separated by null characters which makes them a bit difficult to read. To
view the entries in a slightly more legible form we can pipe the output through
tr
to replace the null characters with new line characters:
cat /proc/$PID/environ | tr '\000' '\n'
References:
man proc
- Server Fault: Environment variables of a running process on Unix?