關於「/proc/[pid]/environ」

測試環境

  • Xubuntu 16.04 amd64 英文界面

執行

$ cat /etc/environment

顯示

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

執行

$ cat /etc/default/locale

顯示

#  File generated by update-locale
LANG="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"

執行

$ locale

顯示

LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

執行

$ cat /etc/profile

顯示

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

執行

$ cat /etc/profile.d/apps-bin-path.sh

顯示

# Expand the $PATH to include /snap/bin which is what snappy applications
# use
PATH=$PATH:/snap/bin

執行

$ dpkg -S /etc/profile.d/apps-bin-path.sh

顯示

snapd: /etc/profile.d/apps-bin-path.sh

執行

$ cat /etc/profile.d/cedilla-portuguese.sh

顯示

# cedilla-portuguese.sh (c) 2015 Canonical
# Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
#
# Released under the GPL
#
# File: /etc/profile.d/cedilla-portuguese.sh
#
# The desired behavior when typing in certain languages is that
# '+c results in the ç character, and not ć. In Portuguese this
# can be achieved by setting LC_CTYPE to either pt_BR.UTF-8 or
# pt_PT.UTF-8. Related files:
# /usr/share/X11/locale/pt_BR.UTF-8/Compose
# /usr/share/X11/locale/pt_PT.UTF-8/Compose
#
# When the selected display language is Portuguese (either Brazilian
# Portuguese or Portuguese as spoken in Portugal), LC_CTYPE inherits
# the desired value from LANG. Due to this file, setting the Regional
# Formats value to Portuguese (Brazil) or Portuguese (Portugal) is
# sufficient to enable the just mentioned behavior, even if the
# display language is something else but Portuguese.
#
if [ "${LC_IDENTIFICATION%_*}" = 'pt' -a "${LANG%_*}" != 'pt' ]; then
    export LC_CTYPE="${LC_IDENTIFICATION%.*}.UTF-8"
fi

執行

$ dpkg -S /etc/profile.d/cedilla-portuguese.sh

顯示

language-selector-common: /etc/profile.d/cedilla-portuguese.sh

探索步驟

執行

$ ps aux | grep '/sbin/init'

顯示

root         1  0.1  0.1 119932  6172 ?        Ss   14:31   0:01 /sbin/init splash

執行

$ sudo strings /proc/1/environ

顯示

HOME=/
init=/sbin/init
recovery=
TERM=linux
drop_caps=
BOOT_IMAGE=/boot/vmlinuz-4.4.0-93-generic
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
rootmnt=/root

執行

$ ps aux | grep login

顯示

root      1018  0.0  0.0  28632  3248 ?        Ss   14:32   0:00 /lib/systemd/systemd-logind
root      1654  0.0  0.0  68152  3592 tty1     Ss   14:32   0:00 /bin/login --

執行

$ pstree 1654 -p

顯示

login(1654)───bash(2504)

執行

$ sudo strings /proc/1654/environ

顯示

LANG=
LC_ADDRESS=
LC_IDENTIFICATION=
LC_MEASUREMENT=
LC_MONETARY=
LC_NAME=
LC_NUMERIC=
LC_PAPER=
LC_TELEPHONE=
LC_TIME=
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TERM=linux
LANGUAGE=
LC_CTYPE=
LC_COLLATE=
LC_MESSAGES=

執行

$ ps aux | grep bash

顯示

user       2504  0.0  0.1  29628  9028 tty1     S+   14:33   0:00 -bash
user       2826  0.0  0.1  30012  9692 pts/4    Ss   14:34   0:00 bash

執行

$ sudo strings /proc/2504/environ

顯示

TERM=linux
LANG=en_US.UTF-8
HOME=/home/user
SHELL=/bin/bash
USER=user
LOGNAME=user
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
MAIL=/var/mail/user
XDG_SESSION_ID=1
XDG_RUNTIME_DIR=/run/user/1000
XDG_SEAT=seat0
XDG_VTNR=1
HUSHLOGIN=FALSE

執行

$ sudo strings /proc/2826/environ

顯示

XDG_SEAT=seat0
XDG_SESSION_ID=c1
LC_IDENTIFICATION=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
DISPLAY=:0
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
UPSTART_JOB=startxfce4
GTK_OVERLAY_SCROLLING=0
JOB=dbus
GNOME_KEYRING_CONTROL=
INSTANCE=
DEFAULTS_PATH=/usr/share/gconf/xubuntu.default.path
LOGNAME=user
LC_TIME=en_US.UTF-8
SHELL=/bin/bash
PATH=/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
LC_NUMERIC=en_US.UTF-8
LC_PAPER=en_US.UTF-8
IM_CONFIG_PHASE=1
QT4_IM_MODULE=fcitx
CLUTTER_IM_MODULE=xim
GLADE_MODULE_PATH=:
XMODIFIERS=@im=fcitx
SESSION=xubuntu
XDG_MENU_PREFIX=xfce-
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
XAUTHORITY=/home/user/.Xauthority
XDG_SESSION_DESKTOP=xubuntu
GDMSESSION=xubuntu
UPSTART_EVENTS=started xsession
LC_MEASUREMENT=en_US.UTF-8
QT_IM_MODULE=fcitx
LC_ADDRESS=en_US.UTF-8
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_CONFIG_DIRS=/etc/xdg/xdg-xubuntu:/usr/share/upstart/xdg:/etc/xdg:/etc/xdg
MANDATORY_PATH=/usr/share/gconf/xubuntu.mandatory.path
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1792
DESKTOP_SESSION=xubuntu
XDG_RUNTIME_DIR=/run/user/1000
GTK_IM_MODULE=fcitx
QT_STYLE_OVERRIDE=gtk
USER=user
PWD=/home/user
VTE_VERSION=4205
LC_MONETARY=en_US.UTF-8
UPSTART_INSTANCE=
GLADE_PIXMAP_PATH=:
HOME=/home/user
QT_ACCESSIBILITY=1
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_DATA_DIRS=/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop:/usr/share
LANGUAGE=en_US
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/user
CLUTTER_BACKEND=x11
LANG=en_US.UTF-8
LC_NAME=en_US.UTF-8
GLADE_CATALOG_PATH=:
SHLVL=0
WINDOWID=73400326
XDG_VTNR=7
GDM_LANG=en_US
GPG_AGENT_INFO=/home/user/.gnupg/S.gpg-agent:0:1
TERM=xterm-256color
SESSIONTYPE=
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-WSv569w6e9
XDG_CURRENT_DESKTOP=XFCE
SESSION_MANAGER=local/user-anywhere:@/tmp/.ICE-unix/2044,unix/user-anywhere:/tmp/.ICE-unix/2044
GNOME_KEYRING_PID=
XDG_SESSION_TYPE=x11

執行

$ ps aux | grep lightdm

顯示

root      1311  0.0  0.1 350520  6224 ?        Ssl  14:32   0:00 /usr/sbin/lightdm
root      1327  2.6  1.8 364468 111608 tty7    Rs+  14:32   1:18 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root      1717  0.0  0.1 228240  6628 ?        Sl   14:32   0:00 lightdm --session-child 12 15

執行

$ sudo strings /proc/1311/environ

顯示

LANG=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_TIME=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

執行

$ pstree 1311 -p

顯示

lightdm(1311)─┬─Xorg(1327)
              ├─lightdm(1717)─┬─upstart(1792)─┬─Thunar(2076)
              │               │               ├─at-spi-bus-laun(2054)─┬─dbus-daemon(2059)
              │               │               │                       ├─{dconf worker}(2055)
              │               │               │                       ├─{gdbus}(2058)
              │               │               │                       └─{gmain}(2056)
              │               │               ├─at-spi2-registr(2063)─┬─{gdbus}(2069)
              │               │               │                       └─{gmain}(2068)
              │               │               ├─bamfdaemon(2005)─┬─{gdbus}(2064)
              │               │               │                  ├─{gmain}(2060)
              │               │               │                  └─{pool}(7021)
              │               │               ├─dbus-daemon(1888)
              │               │               ├─dbus-daemon(1971)
              │               │               ├─dconf-service(2097)─┬─{gdbus}(2099)
              │               │               │                     └─{gmain}(2098)
              │               │               ├─fcitx(1965)
              │               │               ├─fcitx-dbus-watc(1975)
              │               │               ├─gconfd-2(2702)
              │               │               ├─gnome-keyring-d(1992)─┬─{gdbus}(1994)
              │               │               │                       ├─{gmain}(1993)
              │               │               │                       └─{timer}(2008)
              │               │               ├─gnome-terminal-(2817)─┬─bash(2826)───pstree(7022)
              │               │               │                       ├─{dconf worker}(2818)
              │               │               │                       ├─{gdbus}(2820)
              │               │               │                       └─{gmain}(2819)
...略...

執行

$ ps aux | grep gnome-terminal

顯示

user       2817  0.4  0.6 539480 39448 ?        Sl   14:34   0:17 /usr/lib/gnome-terminal/gnome-terminal-server

執行

$ pstree 2817 -p

顯示

gnome-terminal-(2817)─┬─bash(2826)───pstree(6666)
                      ├─{dconf worker}(2818)
                      ├─{gdbus}(2820)
                      └─{gmain}(2819)

執行

$ whereis proc

顯示

proc: /usr/share/man/man5/proc.5.gz

執行

$ dpkg -S /usr/share/man/man5/proc.5.gz

顯示

manpages: /usr/share/man/man5/proc.5.gz

執行

$ whereis procfs

顯示

procfs: /usr/share/man/man5/procfs.5.gz

執行

$ dpkg -S /usr/share/man/man5/procfs.5.gz

顯示

manpages: /usr/share/man/man5/procfs.5.gz

執行

$ file /usr/share/man/man5/procfs.5.gz

顯示

/usr/share/man/man5/procfs.5.gz: symbolic link to proc.5.gz

Manpage

Package

Ubuntu Community Help Wiki

Debian Wiki

相關討論