Some processes are dependent on their environment variable definitions. Knowing the environment variables and values can help you debug or customize a process.
The ps command does not normally show the environment information of a command. The e output modifier at the end of the command adds this information to the output:
$ ps e
Here's an example of environment information:
$ ps -eo pid,cmd e | tail -n 1 1238 -bash USER=slynux LOGNAME=slynux HOME=/home/slynux PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin MAIL=/var/mail/slynux SHELL=/bin/bash SSH_CLIENT=10.211.55.2 49277 22 SSH_CONNECTION=10.211.55.2 49277 10.211.55.4 22 SSH_TTY=/dev/pts/0
Environment information helps trace problems using the apt-get package manager. If you use an HTTP proxy to connect to the Internet, you may need to set environment variables using http_proxy=host:port. If this is not set, the apt-get command will not select the proxy and hence returns an error. Knowing that http_proxy is not set makes the problem obvious.
When a scheduling tool, such as cron (discussed later in this chapter), is used to run an application, the expected environment variables may not be set. This crontab entry will not open a GUI-windowed application:
00 10 * * * /usr/bin/windowapp
It fails because GUI applications require the DISPLAY environment variable. To determine the required environment variables, run windowapp manually and then ps -C windowapp -eo cmd e.
After you've identified the required environment variables, define them before the command name in crontab:
00 10 * * * DISPLAY=:0 /usr/bin/windowapp
OR
DISPLAY=0 00 10 * * * /usr/bin/windowapp
The definition DISPLAY=:0 was obtained from the ps output.