Linux 更改正在运行的进程的环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8589221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing environment variable of a running process
提问by Christian Ammer
I have a script that exports a environment variable and starts some subscripts.
我有一个导出环境变量并启动一些下标的脚本。
export LOGLEVEL="1"
/home/myuser/bin/myscript1.sh
/home/myuser/bin/myscript2.sh
LOGLEVEL
is available for the processes startet from the subscripts. How can I change the environment variable LOGLEVEL
?
LOGLEVEL
可用于从下标开始的进程。如何更改环境变量LOGLEVEL
?
I have tried to set the variable with export LOGLEVEL="5"
but that`s not working.
我试图设置变量,export LOGLEVEL="5"
但这不起作用。
采纳答案by ibid
In general, you can only influence a process's environment variables at the time the process starts up. If you need to communicate a change to a running process, the environment isn't the right tool.
通常,您只能在进程启动时影响进程的环境变量。如果您需要将更改传达给正在运行的进程,则环境不是正确的工具。
However, this questionhas some answers that suggest ways to overcome this limitation.
然而,这个问题有一些答案,建议克服这种限制的方法。
Edited to add in light of discussion in the question's comments: A fairly good way of communicating occasionally changing setup to a running process is to designate a configuration file where the LOGLEVEL value is set, send a SIGHUP to the process, and have the process reread the configuration file upon receipt of SIGHUP.
根据问题评论中的讨论进行编辑:偶尔将设置更改为正在运行的进程的一种相当好的通信方式是指定一个配置文件,其中设置了 LOGLEVEL 值,向进程发送 SIGHUP,然后重新读取进程收到 SIGHUP 后的配置文件。