I need to troubleshoot some problems related to environment variables on a Unix system.
On Windows, I can use a tool such as ProcessExplorer to select particular a process and view values of each environment variable.
How can I accomplish the same thing on Unix? echoing
and env
cmd just show values at present time, but I want to view what values the running process is using currently.
If you want to have pid(s) of a given running executable you can, among a number of other possibilities, use
pidof
:EDIT:
I totally quote Dennis Williamson and Teddy comments to achieve a more readable output. My solution is the following:
Since this question has a unix tag and everyone else has done such a great job addressing linux tag, you can get this information on OS X and other BSD-derived systems using
or
and on Solaris with
Solaris also supports the
/proc
directory if you don't want to remember the obscureps
commmand.As others have mentioned, on Linux, you can look in /proc but there are, depending on your kernel version, one or two limits:
First of all, the environ file contains the environment as it looked when the process was spawned. That means that any changes the process might have made to its environment will not be visible in /proc:
The first shell is a login shell and initially has a very limited environment but grows it by sourcing e.g. .bashrc but /proc does not reflect this. The second shell inherits the larger environment from the start, which it why it shows in /proc.
Also, on older kernels, the contents of the environ file is limited to a page size (4K):
Somewhere between 2.6.9 (RHEL4) and 2.6.18 (RHEL5) this limit was removed...
correct usage of BSD options to do this (at least on linux):
or
and yes, ps manpage is pretty confusing. (via)
While rather sparsely documented, the contents of
/proc/<pid>/environ
will only contain the environment that was used to start the process.If you need to inspect the current state of a process' environment, one way to do that is by using
gdb
.replace PID with the PID of the process you want to see. Every information about a running process is under /proc/PID/ directory
example: cat /proc/32512/environ
Taken from the Archlinux wiki:
You can create a temporary function to parse the values in
/proc/<pid>/environ
. At the terminal prompt:Then with the pid of the process you want, just use:
Under Linux, I'd try having a look at
For Solaris 5.10, this works:
And since my job makes me be an AIX fan boy, let us not forget:
Or as the man page calls it, "Berkeley Standards".
For whatever reason, /proc/PID/environ does not exist in AIX.