不久前,我正在使用 GDB 探索一个简单的 C 程序的 ELF 二进制文件。我看到我printenv在终端中运行时打印的环境变量也出现在我在该终端中运行的 C 程序二进制文件的堆栈顶部。
printenv
Bash 如何实际执行程序,同时所有环境变量也被添加到新进程的堆栈中?简而言之,当我运行这样的程序时会发生什么: ./myprogram
./myprogram
bash process environment-variables elf linux-kernel
bash ×1
elf ×1
environment-variables ×1
linux-kernel ×1
process ×1