gpt4 book ai didi

c - 缺少新的环境变量

转载 作者:行者123 更新时间:2023-12-03 09:50:19 25 4
gpt4 key购买 nike

我在我的程序中设置了一个新的环境变量,但我无法从 shell 中找到它:

int main()
{
if(!setenv("TEST","22222",0)) perror("");
sleep(1000);
return 0;
}

我试试

$ a.out &
[3] 605
$ Success

$ cat /proc/605/environ|grep 2222
$ ps e 605|grep 2222
$

有什么想法吗?非常感谢。

最佳答案

man 5 proc 中所述(注意加粗的段落):

/proc/[pid]/environ

This file contains the initial environment that was setwhen the currently executing program was started viaexecve(2). The entries are separated by null bytes('\0'), and there may be a null byte at the end. Thus,to print out the environment of process 1, you would do:

$ cat /proc/1/environ | tr '\000' '\n'

If, after an execve(2), the process modifies itsenvironment (e.g., by calling functions such asputenv(3) or modifying the environ(7) variabledirectly), this file will not reflect those changes.

关于c - 缺少新的环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64081395/

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