Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Even though /proc/<pid>/environ has a size of 0, there's still information in there. "It makes more sense if you think of it as a window into the kernel. The file doesn't actually contain any data; it just acts as a pointer to where the actual process information resides." [source] – nevets1219 Jun 10 '11 at 17:45

10 Answers 10

up vote 144 down vote accepted
cat /proc/<pid>/environ

If you want to have pid(s) of a given running executable you can, among a number of other possibilities, use pidof:

AlberT$ pidof sshd   
30690 6512 


I totally quote @Teddy comment to achieve a more readable output:

xargs --null --max-args=1 < /proc/self/environ
share|improve this answer
To make it readable, convert the nulls to newlines: cat /proc/17330/environ | tr \\0 \\n – Dennis Williamson Sep 17 '09 at 19:14
I always do xargs --null --max-args=1 echo < /proc/PID/environ – Teddy Oct 29 '09 at 13:08
better use strings, its fast. Cat is still faster :-) – Nikhil Mulley Jan 14 '12 at 19:37

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

ps -p <PID> -wwwe


ps -p <PID> -wwwE

and on Solaris with

/usr/ucb/ps -wwwe <PID>
share|improve this answer
I I run ps -p <PID> -wwwe on OS X 10.6 I get the list of all running processes. the right command is with -E flag, not -e. – drAlberT Sep 18 '09 at 8:17
I realized that -e is equal to -E only if ps is in legacy mode – drAlberT Sep 18 '09 at 8:21
I tested on OS X 10.4, but not 10.5. Updated accordingly. – Gerald Combs Sep 18 '09 at 15:23
This is not perfect. The -E option only reports the initial environment variables. If the variables have been changed by the running process itself (e.g. through the use of the POSIX putenv() function), the changes are not reflected in the output of ps -p <PID> -wwE. – Kal Mar 1 '13 at 7:11

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:

$ cat /proc/$$/environ | wc -c
$ bash
$ cat /proc/$$/environ | wc -c

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):

$ cat /proc/$$/environ | wc -c
$ env | wc -c

Somewhere between 2.6.9 (RHEL4) and 2.6.18 (RHEL5) this limit was removed...

share|improve this answer
cat /proc/PID/environ

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

share|improve this answer

Under Linux, I'd try having a look at

share|improve this answer

correct usage of BSD options to do this (at least on linux):

ps e $pid


ps auxe  #for all processes

and yes, ps manpage is pretty confusing. (via)

share|improve this answer
My Ubuntu smashes the environment variables right up against the command line, without even so much as a space between them, and also truncates to one line on the terminal window. I found ps eww $pid fixes the 2nd problem. – user18911 Dec 3 '13 at 14:42

For Solaris 5.10, this works:

pargs -e <PID>
share|improve this answer

And since my job makes me be an AIX fan boy, let us not forget:

ps eww [pid]

Or as the man page calls it, "Berkeley Standards".

For whatever reason, /proc/PID/environ does not exist in AIX.

share|improve this answer

Taken from the Archlinux wiki:

You can create a temporary function to parse the values in /proc/<pid>/environ. At the terminal prompt:

envof() { sed 's/\x0/\n/g' /proc/${1}/environ; }

Then with the pid of the process you want, just use:

envof <pid>
share|improve this answer

A mac solution, probably other BSDs as well could be something like

pid=28369; ps e $pid | cut -c$(expr 1 + $(ps p $pid|tail +2|wc -c))-

The environment variables are appended to the command line, this removes the command line and we only have the environment variables left.

It is not perfect because they are space separated not LF separated

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.