I was checking environmental variables of bash process of an xterm that was started inside vnc session.

If I check the environmental variables from the bash session itself by running env or cat /proc/pid/environ | strings, it shows all the environmental variables that would generally be set when we do su or ssh i.e., from /etc/profile and .bashrc. But when I do cat /proc/pid/environ | strings from a putty session, it shows completely different variables.

Putting aside why only those specific variables are set, I want to know why environ of same process has different results when checked from different sessions like a double slit experiment. I understand that proc is not real filesystem. But what exactly is happening when I'm querying it and so is proc not realiable way to check remote process environment?

I wrote the question from my phone. So, I don't have any sample output to show. But, I hope you get my question.

  • 1
    /proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces). Commented Jan 3, 2018 at 21:06

1 Answer 1


Here is what I did for a test:

$export test=one
$vim test1

pid = 1200, Stopped the process with CTRL-Z

$cat /proc/1200/environ | strings

Now for second process

$vim test2

pid = 1201, Stopped the process with CTRL-Z

$cat /proc/1201/environ | strings

The user might have changed the environment properties before running the program.

  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – GP92
    Commented Jan 3, 2018 at 18:19
  • 1
    Does the program modify the environment variables? Commented Jan 3, 2018 at 19:27
  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – GP92
    Commented Mar 9, 2018 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .