We are having a lot of trouble interpreting our teacher. We asked for clarification and got the following back from him
For execve, send it a environment you se
I'm a little late to the party here, but if you want to preserve the old environment variables as well as creating your own, use setenv
, and then pass environ
to execve()
.
setenv("dog", "spike", 1);
extern char** environ;
execve(argv[0], argv, environ);
environ
is a variable declared in unistd.h
, and it keeps track of the environment variables during this running process.
setenv()
and putenv()
modify environ
, so when you pass it over execve()
, the environment variables will be just as you'd expect.