Linux:存储环境变量在哪里? [英] Linux: where are environment variables stored?

查看:116
本文介绍了Linux:存储环境变量在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我输入终端,

export DISPLAY=:0.0

...存储该环境变量的shell在哪里?

... where is the shell storing that environment variable?

我正在使用Ubuntu 8.10。我查看了文件〜/ .profile和/ etc / profile,并且没有找到DISPLAY的跟踪。

I'm using Ubuntu 8.10. I've looked in the files ~/.profile and /etc/profile and can find no trace of DISPLAY.

推荐答案

进程的环境变量在运行时存在,并且不会存储在某些文件中。它们存储在进程自己的内存中(这是他们被发现传递给孩子的地方)。但是在

The environment variables of a process exist at runtime, and are not stored in some file or so. They are stored in the process's own memory (that's where they are found to pass on to children). But there is a virtual file in

/proc/pid/environ


$中有一个虚拟文件b $ b

此文件显示调用进程时传递的所有环境变量(除非该进程覆盖其内存部分 - 大多数程序不会)。内核使它们通过该虚拟文件可见。可以列出它们。例如,要查看过程3940的变量,可以执行

This file shows all the environment variables that were passed when calling the process (unless the process overwrote that part of its memory — most programs don't). The kernel makes them visible through that virtual file. One can list them. For example to view the variables of process 3940, one can do

cat /proc/3940/environ | tr '\0' '\n'

每个变量由二进制零分隔下一个。 tr将零替换为换行符。

Each variable is delimited by a binary zero from the next one. tr replaces the zero into a newline.

这篇关于Linux:存储环境变量在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆