From https://unix.stackexchange.com/a/436631/674
the file
/proc/$$/environ
... does not reflect any changes to the environment, but just reports what the program received when it wasexec
ed by the process.
From APUE:
Each program is also passed an environment list. Like the argument list, the environment list is an array of character pointers, with each pointer containing the address of a null-terminated C string. The address of the array of pointers is contained in the global variable
environ
:extern char **environ;
Access to specific environment variables is normally through the
getenv
andputenv
functions, described in Section 7.9, instead of through the environ variable. But to go through the entire environment, theenviron
pointer must be used.
Are /proc/$$/environ
and the global variable environ
independent from each other or consistent with each other?
Do the strings accessed via environ
also not reflect any changes to the environment, but just reports the environment received by execve()
?
Or do the strings accessed via environ
always reflect any change to them, just like that getenv
always get the up-to-date environment strings?
Do the strings accessed via getenv
always reflect any change and are always up-to-date?
Thanks.