[sf-lug] printenv "vs." set [was: Re: shell, man(1) [was: ...

jim jim at well.com
Tue Aug 23 21:25:30 PDT 2016


What a comfy and educational read.


This command worked.
# ps -auxeww
Warning: bad ps syntax, perhaps a bogus '-'? See 
http://procps.sf.net/faq.html
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  24572  2500 ?        Ss   Aug19   0:01 
/sbin/init HOME=/ vt.handoff=7 init=/sbin/init recovery= 
root=UUID=77c4ee5f-0ff2-44bb-9ab3-40759542323c TERM=linux 
BOOT_IMAGE=/boot/vmlinuz-3.2.0-107-generic 
PATH=/sbin:/usr/sbin:/bin:/usr/bin PWD=/ rootmnt=/root

## the environment variables for init include
## HOME, vt.handoff, init, recovery, root, TERM, BOOT_IMAGE, PATH, and 
rootmnt.
##
## 't would be interesting to see which are exported. I'm guessing HOME and
## TERM and PATH.

...
root         2  0.0  0.0      0     0 ?        S    Aug19   0:00 [kthreadd]
...

root       374  0.0  0.0  17228   640 ?        S    Aug19   0:00 
upstart-udev-bridge --daemon 
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
TERM=linux JOB=udev INSTANCE= UPSTART_EVENTS=starting 
UPSTART_JOB=upstart-udev-bridge UPSTART_INSTANCE=

root       377  0.0  0.0  22072  1908 ?        Ss   Aug19   0:00 
/sbin/udevd --daemon 
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
TERM=linux UPSTART_EVENTS=virtual-filesystems UPSTART_JOB=udev 
UPSTART_INSTANCE=

root       651  0.0  0.0  22068  1460 ?        S    Aug19 0:00 
/sbin/udevd --daemon 
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
TERM=linux UPSTART_EVENTS=virtual-filesystems UPSTART_JOB=udev 
UPSTART_INSTANCE=

root      1193  0.0  0.0  19976   968 tty4     Ss+  Aug19   0:00 
/sbin/getty -8 38400 tty4 
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
TERM=linux RUNLEVEL=2 PREVLEVEL=N UPSTART_EVENTS=runlevel not-container 
UPSTART_JOB=tty4 UPSTART_INSTANCE=

whoopsie  1253  0.0  0.0 204468  5212 ?        Ssl  Aug19   0:00 
whoopsie 
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
TERM=linux CRASH_DB_URL=https://daisy.ubuntu.com RUNLEVEL=2 PREVLEVEL=N 
UPSTART_EVENTS=runlevel UPSTART_JOB=whoopsie UPSTART_INSTANCE=


     Now I'm trying to find out how the  init  process
got its environment variables. I read the man page.

# ls /etc/init*

/etc/init/ lists a bunch of conf files, all ASCII, look like shell 
scripts or similar
for various, mainly daemon, processes

/etc/init.d/ lists about 50% symlink files and 50% posix shell scripts.

and /etc/initramfs-tools/ (contents below)

# ls /etc/initramfs-tools/*
/etc/initramfs-tools/initramfs.conf  /etc/initramfs-tools/modules 
/etc/initramfs-tools/update-initramfs.conf

/etc/initramfs-tools/conf.d:
resume

/etc/initramfs-tools/hooks:

/etc/initramfs-tools/scripts:
init-bottom  init-premount  init-top  local-bottom local-premount  
local-top  nfs-bottom  nfs-premount  nfs-top panic


(sigh) looks like a convoluted hunt.



On 08/22/2016 04:24 PM, Akkana Peck wrote:
> Daniel Gimpelevich writes:
>> On Sun, 2016-08-21 at 15:55 -0700, Alex Kleider wrote:
>>> It seems that no variable (shell or environment) can exist except in
>>> the
>>> context of the shell.  So does that make them all shell variables?
>> Variables set from a shell are shell variables. Those that are exported
>> are environment variables in processes that inherit them.
> To expand on that a little more:
>
> The environment is a set of variables inherited from a process by
> its children. So for instance, you might export LESS=-EerX, and then
> every process you execute can check your LESS environment variable
> if it wants. In practice, the only program that's likely to be
> interested in that particular variable is, you guessed it, less.
>
> But there are other environment variables that lots of programs
> might be interested in, like HOME (your home directory), DISPLAY
> (your X display, so X programs know where to pop up windows), PATH
> (where to look for executables), and some optional variables like
> LD_LIBRARY_PATH (where to look for libraries) the various LC_*
> locale variables (which specify what language and character set
> you're using, how you prefer to format dates, and how to sort
> alphabetically), EDITOR and VISUAL (what editor do you prefer), etc.
>
> Environment variables don't have to be capitalized; it's just
> convention.
>
> A program can change its environment, and any changes it makes will
> be passed on to programs it executes. For instance, su - changes
> HOME to the new user's home, so any programs you run inside that su -
> shell will use the new user's home directory, not your original one.
>
> 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
> include even processes that aren't attached to a terminal.
> You'll notice that system processes typically have a much smaller
> environment than the ones you're running inside a shell, because you
> probably set some environment variables in your login shell.
>
>          ...Akkana
>
> _______________________________________________
> sf-lug mailing list
> sf-lug at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/sf-lug
> Information about SF-LUG is at http://www.sf-lug.org/
>





More information about the sf-lug mailing list