setenv from c

Thomas M. Breuel tmb at talcott.UUCP
Mon Sep 23 02:50:36 AEST 1985


In article <2936 at ncsu.UUCP>, rlj at ncsu.UUCP (Rick Johnson) 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.

[I have heard this question before several times, and think that
a posting is therefore warranted. It belongs in net.unix.]

[see also execve(2) and environ(7)]

The environment strings reside in a process' address space,
which makes them inaccessible to any other process. It is therefore
not possible for one process to change the environment variables of
another process except at the time of creation of an immediate child,
when the environment is passed as the third argument to the execve
system call (other varieties of the exec system call (implemented
as library functions) pass the environment data along automatically).

						Thomas.



More information about the Comp.lang.c mailing list