Setting variables for a running process

John Mashey mash at mips.UUCP
Thu May 23 17:44:46 AEST 1985


William Martin writes:
> Is there any way I can change my terminal type (setting the TERM variable)
> while I am inside some other process? ....

No, and it was on purpose. The environment was specifically designed
1) to be mostly the business of user pgms and not the OS 2) to have
the same sort of inheritance semantics as everything else inherited by
a child.  On any UNIX, programs that want to access global state may
easily do so by agreeing on a file name that contains that state,
and agreeing on a signal to alert another process to look at the file.
Environment variables are nothing but implicitly-passed arguments
with usage agreed by programs.

At one point in the design of the environment, it was contemplated that
the environment be a set of global read-write variables, that lived in
a new magic entity inside the kernel.  This was a Wrong Thing, for 2
fundamental reasons:
1) This new magic entity could not reasonably be associated with any
existing entity in the system.  For example, should be owned by a uid?
No, because you might be logged in twice.  Did it belong to a process?
No, because it would be acccessed by more than 1, or would be useless.
DId it belong to a process group? This didn't make sense either.
If some processes have one of these things, what happens when you
fire something up in the background? Does it get its own, or not?
2) Environment variables would suddenly have indeterminate values,
because their modfication sequence was now dependent on process scheduling.
For example, if x were truly global, what result ought to be printed below?
x=10; (x=20)& echo $x

Nevertheless, the original request does illustrate a semantic discontinuity
that has arisen over time.  $TERM was invented originally because it was
becoming obvious that even the simplest functions (like setting tabs) were
terminal-dependent, and that as terminals kept getting smarter they
would only get more different.  At the time, people did not want to chew up the
space inside the kernel to keep a terminal typename inside each tty
structure, and it seemed that we could cover most normal uses of TERM
with environment vars.  Given all the ways that $TERM is now used,
it's no longer clear exactly what it's associativity is.  Maybe it (+ other
useful attributes, like current window size) should belong to each
virtual terminal, which would solve the original problem presented.
-- 
-john mashey
UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!mash
DDD:  	415-960-1200
USPS: 	MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043



More information about the Comp.unix mailing list