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可用于下标中的进程startet。如何更改环境变量LOGLEVEL?
I have tried to set the variable with export LOGLEVEL="5"
but that`s not working.
我试图用导出LOGLEVEL =“5”设置变量,但这不起作用。
2 个解决方案
#1
14
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.
编辑根据问题评论中的讨论添加:偶尔将设置更改为正在运行的进程的一种相当好的方法是指定一个配置文件,其中设置了LOGLEVEL值,向进程发送SIGHUP,并重新读取进程收到SIGHUP后的配置文件。
#2
-5
In linux:
strings –a /proc/<pid_of_the_process>/environ
or
ps eww <pid_of_the_process>
#1
14
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.
编辑根据问题评论中的讨论添加:偶尔将设置更改为正在运行的进程的一种相当好的方法是指定一个配置文件,其中设置了LOGLEVEL值,向进程发送SIGHUP,并重新读取进程收到SIGHUP后的配置文件。
#2
-5
In linux:
strings –a /proc/<pid_of_the_process>/environ
or
ps eww <pid_of_the_process>