View process environment details with proc

0

The process environment consists of all the individual environment variables which are passed on to the program by the shell when the program is launched. This environment can be read and changed by the program during its execution, and can affect how a program is linked or how it executes. For all these reasons it may be important at times to see exactly what the environment contains. The proc filesystem provides the interface to make this happen.

The proc pseudo-file system is used as an interface to kernel data structures. It is commonly mounted at /proc and most of the files inside are read-only. Within proc there exists a subdirectory for every running process on the system identified by its process ID (PID).

Inside each process directory is an environ file which contains the current environment for that process.

/proc/<PID>/environ

This file is limited at this point in time to 4096 characters. Therefore if you have a process with an unusually large environment the data beyond this limit will be truncated.

The environment variable entries are separated by null characters ‘\0‘, which makes it difficult to view the file. The best way to get around this is with the tr command which will replace the the null characters with newline characters ‘\n‘.

Share.