setenv from c

P. D. Guthrie pdg at ihdev.UUCP
Thu Sep 26 00:03:16 AEST 1985


>Rick Johnson (decvax!mcnc!ncsu!rlj) writes:
>> Is it possible to set a csh environment variable within a C program? I know
>> about getenv(), but have failed at attempts to set an environment variable
>> from a C program. Basically, what I want to do is "source" a new environment
>> variable for the current csh process. Any comments or suggestions would be
>> appreciated. Thanks.
>
>A process cannot modify its parent's environment, on purpose.  At one point,
>such a feature was considered, and rejected, because it had no simple,
>understandable semantics.  For example, many otherwise deterministic
>computations turn nondeterministic, depending on process scheduling.
>Consider a pipeline like a | b | c, where all of a, b, c could modify
>their parent's environment, or worse, nohup a& (and logoff).  [Exactly
>what is a modifying?]
>-- 
>-john mashey
>UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!mash
>DDD:  	415-960-1200
>USPS: 	MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043

What about implementing some type of library function and corresponding
shell commands that would load and save an "environment", including
perhaps aliases, sort of like Carnegie-Mellon's PCL-Exec for Tops-20.
This would enable someone to modify the environment from a program and
then have the shell load it in, so file locking could be used to guard
against multiple modifications. I guess this capability crudely exists 
with the source command, but I was thinking of something at a lower level
with less command interpretation. I really liked PCL-Exec, and something
with that power would be great on Unix. Perhaps a signal could be used to
notify a process that it has a new environment?

Paul Guthrie.



More information about the Comp.lang.c mailing list