tags:

views:

110

answers:

3

If we change an environment variable in one process, is the change reflected in other running processes as well?

+3  A: 

No. Each process has its own copy of the environment variables. Child processes can inherit environment variables from their parent processes, but these are copies, and so are not altered if the parent's versions are modified.

Laurence Gonsalves
Nor is the parent's copy altered if the child alters their environment - the two are independent.
Jonathan Leffler
+2  A: 

No. The change is only passed on to child processes, and only those started after the change is made. From Wikipedia:

In all Unix and Unix-like systems, each process has its own private set of environment variables. By default, when a process is created it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child.

Martin B
+1  A: 

An exception is when you invoke a shell script through the . *filename* [*args*] or source *filename* [*args*] syntax. Any changes made to the environment in these subprocesses scripts are also reflected in the original environment.

mobrule
... because it's not a subprocess, it's being interpreted by the shell in the same process.
Miles