⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 138-141.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Basic Linux Commands</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=7//-->

<!--PAGES=138-141//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="136-138.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="141-143.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading13"></A><FONT COLOR="#000077">Environment Variables</FONT></H3>

<P>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 <I>environment variable,</I> 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 &#147;day of the week&#148; (the environment variable); however, we change the data in this variable, from Monday to Tuesday to Wednesday, and so on, as days go by.</P>

<P>To see the list of <I>exported</I> environment variables, type <TT><B>env</B></TT>. A typical output is from the <TT><B>env</B></TT> command looks like this:</P>

<!-- CODE //-->

<PRE>

&#36; 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

</PRE>

<!-- END CODE //-->

<P>The environment variable&#146;s name is on the left and the value held by the variable is on the right. The word &#147;exported&#148; 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&#146;t have the same effect as exported variables.

</P>

<P>The most important variable to note is the <TT><B>PATH</B></TT>, the value of which is your <I>search path</I>. 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.</P>

<P>A longer list of environment variables, consisting of several new variables in addition to the ones shown earlier, is displayed by the command <TT><B>set</B></TT>. Here&#146;s the output from the set command on the same system as the preceding one:</P>

<!-- CODE //-->

<PRE>

&#36; 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=&#36;

PS2=&gt;

SHELL=/bin/sh

TERM=ansi

TZ=EST5EDT

</PRE>

<!-- END CODE //-->

<P>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 &#147;what-floor-am-I-on&#148; becomes an unnecessary piece of information after you leave the building! You may see the same output for both the <TT><B>set</B></TT> and <TT><B>env</B></TT> commands in some cases, but they actually do report slightly different things.</P>

<H3><A NAME="Heading14"></A><FONT COLOR="#000077">Processes and How to Terminate Them</FONT></H3>

<P>In the previous chapter, we learned about the <TT><B>who</B></TT> command, which shows you the login names of everyone who is logged into the system. The <TT><B>who</B></TT> program actually gets its information from the Linux system, which maintains and updates the list of the system&#146;s current users.</P>

<P>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 <I>processes</I>. Every time you enter a command, that&#146;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.</P>

<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">The Process Status Command: ps</FONT></H4>

<P>To find out what processes are running, we use the <TT><B>ps</B></TT> command. &#147;ps&#148; stands for &#147;process status,&#148; not the &#147;post script&#148; you might write at the end of a letter. Remember that <TT><B>ps</B></TT>, like all Linux commands, is lowercase.</P>

<P>Typing <TT><B>ps</B></TT> by itself gives you a concise listing of your own processes. When you don&#146;t specify any options to <TT><B>ps</B></TT>, that&#146;s the default behavior, listing your own processes:</P>

<!-- CODE SNIP //-->

<PRE>

darkstar:~&#36; <TT><B>ps</B></TT>

 PID TTY STAT TIME COMMAND

  41 v01 S   0:00 -bash

 134 v01 R   0:00 ps

</PRE>

<!-- END CODE SNIP //-->

<P>The information in the first column, headed <TT><B>PID</B></TT>, 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&#146;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&#146;s faster and easier that way.</P>

<P>The <TT><B>TTY</B></TT> column shows you which terminal the process was started from. You will see your own terminal listed when you try the <TT><B>ps</B></TT> command.</P>

<P>The <TT><B>STAT</B></TT> column give the status of the process. The two most common entries in the status column are <TT><B>S</B></TT> for <I>sleeping</I> and <TT><B>R</B></TT> for <I>running</I>. A sleeping process is one that isn&#146;t currently active. However, don&#146;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.</P>

<P>The <TT><B>TIME</B></TT> column shows the amount of system time used by the process. Clearly, neither of our processes is taking up any appreciable system time! That&#146;s often the case with modern machines, as most processes execute so quickly that the time column scarcely moves above a single digit.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="136-138.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="141-143.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -