On Wed, Apr 09, 2008 at 06:13:20PM -0600, BC wrote:
> Ahhh, now I get it. I simply presumed that a running process could read
> 'the environment' and there is only one 'environment'. So each process
> has its own environment, too. Cute.
Environment variables are part of the state space of a Unix process, much
like the set of open file descriptors, resource limits, uid/gid/euid/egid,
supplementary group memberships, nice level, current working directory etc.
Child processes inherit copies of this state space across fork()-like system
calls, so that if one process sets an environment variable, its subsequently
spawned children and the childrens' children and so on will also have that
variable.
Children can change or unset variables, which will affect what environment
their subsequently spawned children inherit, but they can't change the
environment of the parent.
This is also why the Midnight Commander, unlike the Norton Commander under
DOS, can't (trivially) be used as a semi-graphical "cd" command: it can't
make its parent process, the shell it is started from, change its working
directory. When mc exits, the spawning shell resumes where it left of,
including the working directory. (There is a shell alias based workaround
for people who just have to use mc instead of cd.)
> Now your argument against using the environment for too much, makes
> better sense to me.
Sure, it shouldn't be used for "too much". Just for the things it's
practical to use it for. :)
Andras
--
Andras Korn <korn at chardonnay.math.bme.hu>
<http://chardonnay.math.bme.hu/~korn/> QOTD:
I brake for hallucinations.
_______________________________________________
spamdyke-users mailing list
[email protected]
http://www.spamdyke.org/mailman/listinfo/spamdyke-users