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

查看:62
本文介绍了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

这个文件显示了调用进程时传递的所有环境变量(除非进程覆盖了它的那部分内存——大多数程序不会).内核通过该虚拟文件使它们可见.可以一一列举.例如查看进程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 '' '
'

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

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

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

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