改变正在运行的进程的环境变量 [英] 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
可用于下标中的进程启动。我如何更改环境变量 LOGLEVEL
?
LOGLEVEL
is available for the processes startet from the subscripts. How can I change the environment variable LOGLEVEL
?
我已经尝试使用导出LOGLEVEL =5
,但这不起作用。
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.
但是,这个问题有一些答案建议了克服这个限制的方法。
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屋!