更改正在运行的进程的环境变量
我有一个导出环境变量并启动一些下标的脚本。
export LOGLEVEL="1"
/home/myuser/bin/myscript1.sh
/home/myuser/bin/myscript2.sh
LOGLEVEL
可用于从下标启动的进程。如何更改环境变量LOGLEVEL
?
我尝试使用 export LOGLEVEL="5"
设置变量,但这不起作用。
I have a script that exports an environment variable and starts some subscripts.
export LOGLEVEL="1"
/home/myuser/bin/myscript1.sh
/home/myuser/bin/myscript2.sh
LOGLEVEL
is available to the processes started from the subscripts. How can I change the environment variable LOGLEVEL
?
I have tried to set the variable with export LOGLEVEL="5"
but that`s not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您只能在进程启动时影响进程的环境变量。如果您需要向正在运行的进程传达更改,那么环境不是合适的工具。
但是,这个问题有一些答案建议克服此限制的方法。
根据问题评论中的讨论进行编辑以添加:偶尔更改设置与正在运行的进程进行通信的一种相当好的方法是指定一个设置了 LOGLEVEL 值的配置文件,向进程发送 SIGHUP,然后重新读取进程收到 SIGHUP 后的配置文件。
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.
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.