gpt4 book ai didi

winapi - 以编程方式获取另一个进程的环境变量?

转载 作者:行者123 更新时间:2023-12-02 06:32:18 25 4
gpt4 key购买 nike

我想从进程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/

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