All exec*() functions are front ends for execve().
Quick example of execve, where e means you pass in the
environment --
char *Environment[] = {"TERM=vt100", 0};
char *Commandline[] = {"telnet", "localhost", 0};
execve(Commandline[0], Commandline, Environment);
My apologies if the parameters are not quite correct.
What's interesting to note is the first parameter is the
name of the program, when it's also the first element of
Commandline[]. I wonder why they made this necessary.
Also note exec*() is one-way unless it fails. If successful,
your program no longer exists. Any code below the call
will never be reached (unless the exec is unsuccessful).
Different exec*() functions are more simple to use,
such as execvp(), which doesn't require the environment
array. In its case, I believe it just gets the same environment
as when the first program was created. Note any
putenv()'s before the execvp() are ignored. However, if
you call the second program with system(), the putenv()
calls work.
Sorry if the above is confusing / rambling. I'm self-taught
for the most part regarding this subject, and some of
my facts may be wrong or I may be remembering them
wrong. The Linux box here is off at the moment, so I
can't check the man pages.
**
If someone could give a good explaination of what the
stack looks like after making an execve(), I would
appreciate it. My observations were confusing.
A map of where the command line arguments and
environmental variables are would be tremendously
appreciated. Thanks!
**
Hope this helps!
~Patrick