Friday, January 27, 2012

Power of Proc-5: Linux process environment details

Using proc file system in Linux , it is possible to get the environment details of a running process. It indicates the environment setting when the process was executed.

/proc/[pid]/"environ" file contains all the environment variable information about the chosen process.

For example:
1. Chose a process , lets chose crond
2. Identify process ID of crond



proctest# ps -eaf | grep cron
root      1379     1  0  2011 ?        00:00:07 crond
process ID is 1379

3.  Get the process environment details, by looking at content of "/proc/[pid]/environ" file


proctest# cat /proc/1379/environ
TERM=linux
PATH=/sbin:/usr/sbin:/bin:/usr/binrunlevel=3
RUNLEVEL=3
LANGSH_SOURCED=1
PWD=/
LANG=en_US.UTF-8previous=NPREVLEVEL=NCONSOLETYPE=vtSHLVL=3UPSTART_INSTANCE=UPSTART_EVENTS=runlevelUPSTART_JOB=rc_=/usr/sbin/crond
proctest#


This is very useful when you have process already running and want to capture the environment details or  verify the environment during debugging of an application.

Pin It
Related Posts Plugin for WordPress, Blogger...