我想从进程B获取进程A的环境变量? 与A、B没有任何关系。 不是系统环境变量,而是已经传递给进程的环境变量!
在 Linux 或 Windows 中
最佳答案
在 Linux 中,您可以通过读取(或映射)/proc/[pid]/environ 来完成此操作。来自 proc(5 ):
/proc/[pid]/environ
This file contains the environment for the process. 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; echo) | tr '\000' '\n'
关于winapi - 以编程方式获取另一个进程的环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11627682/