Viewing the environment of a Linux or Solaris process


Each process that is started on a Linux and Solaris hosts contains a default environment. This environment contains several variables such as the PATH to search for executables, a HOME variable to indicate where a users home directory is located, and variables such as LANG to describe the locale in use. The variables are unique to the shell in use (I recently learned that not all shells set HOSTNAME), and can be adjusted with the the bash export command, or the csh setenv command. After a process starts, it is sometimes useful to be able to view the environment of a process. On Solaris hosts, you can see the environment of a process by invoking pargs with the “-e” (print the environment) option:

$ pargs -e 18167

18167: /usr/lib/ssh/sshd
envp[0]: LANG=C
envp[1]: PATH=/usr/sbin:/usr/bin
envp[2]: SMF_FMRI=svc:/network/ssh:default
envp[3]: SMF_METHOD=/lib/svc/method/sshd start
envp[4]: SMF_RESTARTER=svc:/system/svc/restarter:default
envp[5]: TZ=US/Eastern

On Linux hosts, you can cat /proc/$PID/environ, where $PID is the process id you are interested in:

$ cd /proc/self

$ cat environ

USER=mattyLOGNAME=mattyHOME=/home/mattyPATH=/usr/bin:/bin:/usr/sbin:/sbin
MAIL=/var/mail/mattySHELL=/bin/bashSSH_CLIENT=10.10.1.10 49550 22
SSH_CONNECTION=10.10.1.10 49550 10.10.1.11 22SSH_TTY=/dev/pts/0TERM=xterm-color

The Solaris output is a bit prettier, but they both contain the information you need to derive the environment of a process.

This article was posted by Matty on 2006-07-04 10:49:00 -0400 -0400