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

📄 583-586.html

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

<HEAD>

<TITLE>Using Linux:Managing the Kernel</TITLE>

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

 -->




<!--ISBN=0789716232//-->

<!--TITLE=Using Linux//-->

<!--AUTHOR=William Ball//-->

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

<!--IMPRINT=Que//-->

<!--CHAPTER=32//-->

<!--PAGES=583-586//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="581-583.html">Previous</A></TD>

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

<TD><A HREF="586-589.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Viewing Processes with the <I>top</I> Command

</FONT></H4>

<P><TT>top</TT> is a dynamic process-viewing utility. It essentially combines the output of several other utilities in a compact and relatively easy-to-read format. <TT>top</TT> provides the means to sort processes by the percentage of processor time they use, the memory they use, or the total amount of time they have run on the system.</P>

<P>To start <TT>top</TT>, simply type <TT><B>top</B></TT> from a command prompt. A screen comes up showing you the memory allocated, the system-uptime and load averages, and a list of processes sorted by the amount of CPU time they are using.</P>



<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">

<TR><TD><FONT SIZE="+1"><B>CPU time vs. how long a process has been running</B></FONT>

<BR>CPU time for a process is a reasonable estimate of how long a process has run on the processor. This is different from how long the program has been running, from a human perspective, because there are a lot of other programs running at the same time. Time used gives an estimate on how far along the process is if it had been the only thing running on the system.</TABLE>



<P><TT>top</TT>&#146;s commands are pretty simple, and are summarized in Table 32.2.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>TABLE 32.2</B> Command summary for the <I>top</I> utility

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">Command

<TH WIDTH="60%" ALIGN="LEFT">Usage

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>h</TT>

<TD>Help. This brings up a detailed help screen.

<TR>

<TD VALIGN="TOP"><TT>M</TT>

<TD>Sorts processes by memory used. Use this to find the program that is using the most memory on your system.

<TR>

<TD VALIGN="TOP"><TT>S</TT>

<TD>Changes <TT>top</TT>&#146;s display from current to cumulative mode when displaying CPU time used by a process. By default, <TT>top</TT> displays only the CPU time a process has used from the time <TT>top</TT> was last checked. With this flag, <TT>top</TT> displays all the CPU time a process has used since the program was started. There are always some inaccuracies here&#151;<TT>X</TT>, for example, always seems to display cumulative time on my system, no matter what the flag is set to.

<TR>

<TD VALIGN="TOP"><TT>T</TT>

<TD>Sorts by the amount of processor time the process has used, either cumulative, or since the last refresh of the <TT>top</TT> screen.

<TR>

<TD VALIGN="TOP"><TT>P</TT>

<TD>Sorts the display by the percentage CPU time a process has had since the last time the <TT>top</TT> display refreshed itself.

<TR>

<TD VALIGN="TOP"><TT>r</TT>

<TD>Re-<TT>nices</TT> a process. The <TT>nice</TT> value of a process is the priority the process has in the system, ranging from 32 to &#150;32. The lower the <TT>nice</TT> value, the higher the process&#146;s priority in the system. Only processes owned by root can have negative <TT>nice</TT> values. You must be the owner of the process or logged on as root to change its <TT>nice</TT> value.

<TR>

<TD VALIGN="TOP"><TT>k</TT>

<TD>Kills a process. This sends the appropriate signal to a process to indicate that it should finish processing and exit. <TT>top</TT> enables you to send different signals to a process&#151;it prompts you for the one to send. Normally, the <TT>TERM</TT> signal <TT>(15)</TT> works fine to terminate a process. Processes that are hung, or those that ignore the <TT>TERM</TT> signal, however, may need some stronger persuasion to terminate, such as the <TT>KILL</TT> signal <TT>(9)</TT>. This signal makes Linux unconditionally terminate the process.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>



<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">

<TR><TD>

<P><B>Case sensitivity with <TT>top</TT></B><BR><TT><B>top</B></TT>&#146;s commands are case-sensitive!</TABLE>



</P>

<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">Viewing Processes with the <I>ps</I> Command

</FONT></H4>

<P><TT>ps</TT> is the UNIX standard utility used to manage processes on a system. This utility provides pretty much the same functionality as <TT>top</TT>, but is command-line driven rather than using a primitive text interface.</P>

<P>The <TT>ps</TT> command alone produces a list of all processes owned by the current user, along with the process ID, the terminal the process is running on, the process status, the CPU time used, and the command line and name of the process itself.</P>

<P>At it&#146;s most basic, the output of <TT>ps</TT> looks like this:</P>

<!-- CODE SNIP //-->

<PRE>

[jwalter&#64;irksome jwalter]$ ps

  PID TTY STAT  TIME COMMAND

 1296  p1 S    0:00 -bash

 1310  p1 R    0:00 ps

[jwalter&#64;irksome jwalter]$

</PRE>

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

<P>I own only two processes on this system: <TT>bash</TT> (my shell) and <TT>ps</TT> (the program that produced this data). The <TT>STAT</TT> column tells me what the processes are currently up to&#151;whether the program is running (<TT>R</TT>), sleeping (<TT>S</TT>), stopped (<TT>T</TT>), or zombified (<TT>Z</TT>). While the Linux kernel does a good job of keeping the system clean, once in a while the system administrator should go around and clean up any remaining zombie processes.</P>

<P><FONT SIZE="+1"><B> <I>ps</I> Command-Line Parameters

</B></FONT></P>

<P>The <TT>ps</TT> utility accepts command-line parameters without requiring a hyphen, like so:</P>

<!-- CODE SNIP //-->

<PRE>

ps &lt;options&gt;

</PRE>

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

<P><TT>ps</TT> command-line options are discussed in Table 32.3.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>TABLE 32.3</B> <I>ps</I> command-line options

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">Option

<TH WIDTH="60%" ALIGN="LEFT">Effect

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>a</TT>

<TD>Lists all processes, even those not owned by the user running <TT>ps</TT>.

<TR>

<TD VALIGN="TOP"><TT>x</TT>

<TD>Lists processes that don&#146;t have a controlling terminal (daemon programs and so on).

<TR>

<TD VALIGN="TOP"><TT>u</TT>

<TD>Prints user ID and memory usage information. This looks remarkably like the process list for <TT>top</TT>.

<TR>

<TD VALIGN="TOP"><TT>j</TT>

<TD>Prints job information. This lists the process user and group IDs in numerical format, along with the parent process IDs.

<TR>

<TD VALIGN="TOP"><TT>f</TT>

<TD>Prints process information in a tree format showing parent processes and their relations.

<TR>

<TD VALIGN="TOP"><TT>t</TT>

<TD>Prints only process attached to the terminal name that immediately follows. The preceding <TT>tty</TT> is assumed, so <TT>ps tS1</TT> would list all processes with <TT>ttyS1</TT> as the owning terminal.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>Of course, there are plenty of other options listed in the man pages for <TT>ps</TT>. The ones in Table 32.3 are simply the ones that systems administrators use the most often.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="581-583.html">Previous</A></TD>

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

<TD><A HREF="586-589.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 + -