gpt4 book ai didi

c - 为什么 execve 忽略环境参数?

转载 作者:行者123 更新时间:2023-11-30 17:33:29 25 4
gpt4 key购买 nike

假设我们有程序1:

int main(void) {
char *env[2];

env[0] = "PATH=/";
env[1] = NULL;

execve("/program2", NULL, env);

exit(0);
}

我们还有程序2:

int main(void) {
exit(0);
}

对此进行调试,在执行的新进程(program2)中实际上并未修改 PATH。

最佳答案

Debugging this, PATH isn't actually modified in the new process (program2) that is executed.

这不是真的。请注意,p environ 不起作用,而x 0x8049650(地址environ@@GLIBC_2.0,从info var environ 获得) 的作用是:

(gdb) p environ$1 = (char **) 0x0(gdb) p/x &environ$2 = 0xf7fbfd44(gdb) x 0x80496500x8049650 : 0xffffdf18(gdb) x/s **0x80496500xffffdfe8:      "PATH=/"

关于c - 为什么 execve 忽略环境参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23749583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com