The call that starts a program
The system call execve takes three arguments: the path of the program to run, the argument vector, and the environment vector. The kernel reads the executable, replaces the memory of the calling process with the new program, and places the strings from the two vectors on the new stack. The process keeps its PID. It also keeps the working directory and every open file descriptor that does not have the close-on-exec flag set. Only the program image and the environment change.
For an ordinary command, bash does not call execve in its own process. It first calls fork, which creates a child that starts as a copy of the shell, and the child then calls execve. The parent waits for the child to finish and reads its exit status. The exec builtin skips the fork and replaces the shell itself, which is why exec does not return to the prompt.
What the kernel places in the new process
The kernel copies each environment string into the new process memory, in the order that bash passed them. The C library keeps a pointer to the array, usually called environ, and functions such as getenv search that array. This is why a program can read its environment with no special privilege and no connection to the shell. Calling setenv inside the program changes only the in-process copy, which vanishes when the program exits.
Watching the arrays with strace
strace prints system calls as they happen. With the -e trace=execve filter it shows only the program starts, and with -v it prints the full argument and environment arrays without shortening them. This is the most direct way to see which variables a child actually received, and it is more reliable than reading the shell configuration files.
strace -v -e trace=execve env -i A=1 env 2>&1 | tail -n 2The traced call shows the environment array that env passed to the inner program. Here env -i cleared the inherited environment, so the only entry is the one you named. The trace output goes to standard error, which is why the command redirects it before the pipe.
A case: a service that cannot find a tool
Consider a job that works in a terminal but fails when a scheduler starts it. The error says that a tool named deploy-helper is not found. The first assumption is usually that the tool is missing, but the simpler explanation is that the job has a different PATH. A scheduler or a service manager usually starts the job with a small, fixed environment, and the terminal adds directories that the scheduler never sees.
The investigation follows the array. Start the job with the same clean environment you expect it to have, using env -i PATH=/usr/bin:/bin, and check whether the tool is found. Next, look at the environment block of the running process through /proc/PID/environ to see what the kernel actually received. Finally, compare the two lists. The difference is the missing directory, and the fix is to set PATH inside the job, not to copy the whole terminal environment into the scheduler.
Copying your full interactive environment into a service is a common fix that creates new problems. Secrets, a personal PATH, and a locale that the service does not need all come along. Pass only the variables that the program requires.
Limits and errors
The arrays have limits. A single string can be at most 128 KiB, and the combined arguments and environment must fit within the kernel limit for the stack. When the total is too large, execve fails with the error E2BIG, which bash reports as an argument list that is too long. A program that exports a very large value into every child can hit this limit without any obvious change, so keep large data in files rather than in variables.
Permission errors and missing files also come from execve. A missing interpreter in a script's first line produces a confusing error, because the kernel reports the script path even though the problem is the interpreter. Reading the system call trace resolves the question quickly, because each failed call shows the path it tried.