-->
Previous Table of Contents Next


Environment Variables

When you log in, Linux keeps a number of useful data items in the background ready for the system to use. The actual data is held in something called an environment variable, whose name is often descriptive or mnemonic. In fact, this is no different from the way you and I remember things. We know that there is always a piece of information called “day of the week” (the environment variable); however, we change the data in this variable, from Monday to Tuesday to Wednesday, and so on, as days go by.

To see the list of exported environment variables, type env. A typical output is from the env command looks like this:


$ env

FMHOME=/frame

HOME=/usr/tparker

HUSHLOGIN=FALSE

HZ=100

LOGNAME=tparker

MAIL=/usr/spool/mail/tparker

PATH=:/frame/bin:/bin:/usr/bin:/usr/tparker/bin:.

SHELL=/bin/sh

TERM=ansi

TZ=EST5EDT

The environment variable’s name is on the left and the value held by the variable is on the right. The word “exported” is used here to mean something special; when an environment variable is exported, it is available to every program and utility on the system that you start. It stays available until you log off. You can define variables that are effective only for a single program or that don’t have the same effect as exported variables.

The most important variable to note is the PATH, the value of which is your search path. As we will see in the next chapter, when you type a command, Linux searches every place listed in your search path for that command.

A longer list of environment variables, consisting of several new variables in addition to the ones shown earlier, is displayed by the command set. Here’s the output from the set command on the same system as the preceding one:


$ set

FMHOME=/frame

HOME=/usr/tparker

HUSHLOGIN=FALSE

HZ=100

IFS=



LOGNAME=tparker

MAIL=/usr/spool/mail/tparker

MAILCHECK=600

OPTIND=1

PATH=:/frame/bin:/bin:/usr/bin:/usr/tparker/bin:.

PS1=$

PS2=>

SHELL=/bin/sh

TERM=ansi

TZ=EST5EDT

The new variables that appear on the list are local: They have not been marked for export. For more information on exporting variables, see Chapter 10. You can think of local variables as items of information needed for only a certain time or location. For instance, remembering the variable “what-floor-am-I-on” becomes an unnecessary piece of information after you leave the building! You may see the same output for both the set and env commands in some cases, but they actually do report slightly different things.

Processes and How to Terminate Them

In the previous chapter, we learned about the who command, which shows you the login names of everyone who is logged into the system. The who program actually gets its information from the Linux system, which maintains and updates the list of the system’s current users.

In fact, Linux keeps much more detailed records about what is happening on the system than just who is logged in. Because Linux is a multitasking system in which many programs or program threads may be running simultaneously, Linux keeps track of individual tasks or processes. Every time you enter a command, that’s a process. Whenever the system does anything, that, too, is a process. Essentially, everything that Linux does is called a process, and there can be dozens of processes running at the same time.

The Process Status Command: ps

To find out what processes are running, we use the ps command. “ps” stands for “process status,” not the “post script” you might write at the end of a letter. Remember that ps, like all Linux commands, is lowercase.

Typing ps by itself gives you a concise listing of your own processes. When you don’t specify any options to ps, that’s the default behavior, listing your own processes:


darkstar:~$ ps

 PID TTY STAT TIME COMMAND

  41 v01 S   0:00 -bash

 134 v01 R   0:00 ps

The information in the first column, headed PID, is important. This is the Process ID number, a unique number assigned to each process and which Linux uses to identify that particular process. You must know a process’s PID to be able to kill it. Every process on the system has a PID, and the numbers range from 0 to 65,565 then restart from the beginning, making sure each number is used only once at any one time. Linux uses numbers instead of names for each process because it’s faster and easier that way.

The TTY column shows you which terminal the process was started from. You will see your own terminal listed when you try the ps command.

The STAT column give the status of the process. The two most common entries in the status column are S for sleeping and R for running. A sleeping process is one that isn’t currently active. However, don’t be misled. A sleeping process might just be taking a very brief catnap! In fact, a process can switch between sleeping and running many times every second.

The TIME column shows the amount of system time used by the process. Clearly, neither of our processes is taking up any appreciable system time! That’s often the case with modern machines, as most processes execute so quickly that the time column scarcely moves above a single digit.


Previous Table of Contents Next