/proc/<pid>/environ does not update (as I understand it, the file contain the initial environment of the process).
How can I read a process's current environment?
As far as the kernel is concerned, the environment only appears as the argument of the
You can read the initial environment of a process from
If a process changes it's environment, then in order to read the environment you must have the symbol table for the process and use the
That's the answer. Now for some notes.
The above assumes that the process is POSIX compliant, meaning that the process manages it's environment using a global variable
The initial environment for a process is passed to the process in a fixed length buffer on the process's stack. (The usual mechanism that does this is
If the process uses
Now if the new process is only
Finally, the POSIX
It is updated as and when the process acquires/deletes its environment variables. Do you have a reference, which states the
The above will print the environment variables of the process in the ps output format, text-processing (parsing/filtering) is required to see the environment variables as a list.
Solaris (not asked, but for reference I will post here):
EDIT: /proc/pid/environ is not updated! I stand corrected. Verification process is below. However, the children from which the process are fork'd inherit the process environment variable and it is visible in their respective /proc/self/environ file. (Use strings)
With in the shell: here xargs is a child process and hence inherits the environment variable and also reflects in its
Checking it from other session, where the terminal/session is not the child process of the shell where the environment variable is set.
Verifying from another terminal/session on the same host:
terminal1: : Note that printenv is fork'd and is a child process of bash and hence it reads its own environ file.
terminal2: on the same host -- do not launch it with in the same shell where the above variable was set, launch the terminal seperately.