改变正在运行的进程的环境变量 [英] Changing environment variable of a running process
问题描述
我有一个出口环境变量,并开始了一些标脚本。
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
可从下标过程startet。如何更改环境变量 LOGLEVEL
?
LOGLEVEL
is available for the processes startet from the subscripts. How can I change the environment variable LOGLEVEL
?
我曾尝试设定出口LOGLEVEL变量=5
但that`s无法正常工作。
I have tried to set the variable with export LOGLEVEL="5"
but that`s not working.
推荐答案
在一般情况下,你只能在进程启动时间影响一个进程的环境变量。如果你需要一个变化传达给正在运行的进程,环境是不正确的工具。
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.
然而,<一个href=\"http://stackoverflow.com/questions/205064/is-there-a-way-to-change-another-processs-environment-variables\">this问题有一些答案的建议如何克服这种限制。
However, this question has some answers that suggest ways to overcome this limitation.
编辑,以在在问题的意见讨论光补充:沟通偶尔改变设置到正在运行的进程的一个比较好的方法是指定地方LOGLEVEL值设置的配置文件,发送SIGHUP的过程,并有这个过程在收到SIGHUP的读取配置文件。
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.
这篇关于改变正在运行的进程的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!