Let say we entered wget
command. My understanding is that shell calls fork()
and a child process is created. At this moment before exec()
is called, the child process is identical to the parent process except for things like process ID.
Then when exec()
is called, kernel replaces the child process' image with wget
's.
But environment variable is not overwritten, so I am confused what are replaced and what are retained from the parent process.
Below is my humble attempt to answer your question. However, I am afraid that the answer can be too overwhelming.
Effect of exec() on process attributes
Also, do visit execve man page.