Linux – /proc/pid/environ missing variables

environment-variableslinuxprocess

google is giving no love on this one today, so I turn to the experts…

I'm currently hacking together a script that relies on the /proc/pid/environ feature in Linux (RHEL 4) to check for a particular environment variable. Trouble is, it seems certain environment variables aren't showing up in there for some reason.

Example:

create some test vars:
$ export T_1=testval TEST_1=testval T=testval TESTING_LONGEST=testval

open a subshell:
$bash

$ cat /proc/self/environ|tr "\0" "\n"|grep testval
TESTVARIABLE_LONGEST=testval
T=testval

hmm… where did T_1 and TEST_1 go?? what rules govern this strange universe?

Thanks in advance,
Josh

UPDATE:

I have been able to reproduce this issue on various RHEL versions and with various users, but it seems it is unique to Bash (I'm using 3.0). ksh does not show this behavior.

Best Answer

Have a look at Environment variables of a running process on Unix? ; it notes that /proc/*/environ is limited to 4096 bytes on some kernels, and that it doesn't display env vars that were changed in that shell.