[sf-lug] to see the environments of all processes

Michael Paoli Michael.Paoli at cal.berkeley.edu
Mon Aug 22 23:52:10 PDT 2016


> From: "Akkana Peck" <akkana at shallowsky.com>
> Subject: Re: [sf-lug] printenv "vs." set [was: Re: shell, man(1) [was: ...
> Date: Mon, 22 Aug 2016 10:24:29 -0600

> You can examine the environments of all of your running processes with
> ps eww
> -- e tells ps to print the environment, w tells it you need lines
> wider than the terminal, and the second w tells it you need lines
> *really* wider than the terminal. Make it axeww if you want to see
> the environments of all processes running on your system: a tells ps
> to show processes owned by anyone, not just you, and x says to

Generally need to have sufficient privilege - e.g. be superuser/root,
to examine the environment of processes not owned by the invoking user.

E.g. I gave earlier example:
# ps lwwwep 1
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0  15492  1528 -      Ss   ?          2:39  
init [2]           SHLVL=1 HOME=/ init=/lib/sysvinit/init TERM=linux  
drop_caps= BOOT_IMAGE=/vmlinuz-3.16.0-4-amd64  
PATH=/sbin:/usr/sbin:/bin:/usr/bin PWD=/ rootmnt=/root
#
If, instead, I do that as a mere mortal user:
$ ps lwwwep 1
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0  15492  1528 -      Ss   ?          2:39 init [2]
$
I don't get to see the environment information.
Essentially, environments may contain privileged information, hence access
to that is limited.
The situation is similar if we wish to look via the /proc file system:
$ ls -ld /proc/1/environ
-r-------- 1 root root 0 Aug 22 23:36 /proc/1/environ
$
# < /proc/1/environ tr '\0' '\012'
SHLVL=1
HOME=/
init=/lib/sysvinit/init
TERM=linux
drop_caps=
BOOT_IMAGE=/vmlinuz-3.16.0-4-amd64
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
rootmnt=/root
#





More information about the sf-lug mailing list