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

📄 ch38_05.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 38] 38.5 The ps Command </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:49:38Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch38_01.htm"TITLE="38. Starting, Stopping, and Killing Processes"><LINKREL="prev"HREF="ch38_04.htm"TITLE="38.4 Subshells "><LINKREL="next"HREF="ch38_06.htm"TITLE="38.6 The Controlling Terminal "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch38_04.htm"TITLE="38.4 Subshells "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 38.4 Subshells "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 38<BR>Starting, Stopping, and Killing Processes</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch38_06.htm"TITLE="38.6 The Controlling Terminal "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 38.6 The Controlling Terminal "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1940">38.5 The ps Command </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-42531"></A><ACLASS="indexterm"NAME="AUTOID-42533"></A><ACLASS="indexterm"NAME="AUTOID-42535"></A>The <EMCLASS="emphasis">ps</EM> command produces a report summarizing execution statistics for currentprocesses. The bare <EMCLASS="emphasis">ps</EM> commandlists the process ID, the terminal the command was started from, howmuch CPU time it has used, and the command itself. The output lookssomething like this (it differs from system to system):</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">PID TT STAT  TIME COMMAND 1803 p5 IW    0:00 -csh (csh) 1883 p5 IW    0:04 vi outline 1811 p6 IW    0:01 -csh (csh) 5353 p6 TW    0:01 vi 4890</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-42542"></A><ACLASS="indexterm"NAME="AUTOID-42544"></A>By default, <EMCLASS="emphasis">ps</EM> lists only your own processes.There are many times, though, when it's desirable to have a morecomplete listing with alot of data about all of the processes currently running on the system.The options required to do this differ between BSD UNIX and System V. Under BSD UNIX,the command is <EMCLASS="emphasis">ps -aux</EM>, which produces a table of all processes,arranged in order of decreasing CPU usage at the moment when the <EMCLASS="emphasis">ps</EM>command was executed. [The <EMCLASS="emphasis">-a</EM> option gives processes belongingto all users, <EMCLASS="emphasis">-u</EM> gives a more detailed listing, and <EMCLASS="emphasis">-x</EM>includes processes that no longer have a<SPANCLASS="link">controlling terminal (<ACLASS="linkend"HREF="ch38_06.htm"TITLE="The Controlling Terminal ">38.6</A>)</SPAN>.<EMCLASS="emphasis">-TOR</EM>&nbsp;]It is often useful to pipe this output to<SPANCLASS="link"><EMCLASS="emphasis">head</EM> (<ACLASS="linkend"HREF="ch25_20.htm"TITLE="Printing the Top of a File ">25.20</A>)</SPAN>,which will display the most active processes:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ps -aux | head -5</B></CODE>USER       PID %CPU %MEM   SZ  RSS TTY STAT  TIME COMMANDmartin   12923 74.2 22.5  223  376 p5  R     2:12 f77 -o foo foo.Fchavez   16725 10.9 50.8 1146 1826 p6  R N  56:04 g94 HgO.datng       17026  3.5  1.2  354  240 co  I     0:19 vi benzene.txtgull      7997  0.2  0.3  142   46 p3  S     0:04 csh</PRE></BLOCKQUOTE></P><PCLASS="para">The meanings of the fields in this output (as well as others displayed by the <EMCLASS="emphasis">-l</EM> option to <EMCLASS="emphasis">ps</EM>) are given in<ACLASS="xref"HREF="ch38_05.htm#UPT-ART-1940-TAB-0"TITLE="ps Command Output Fields">Table 38.1</A>.</P><PCLASS="para">The first line of this output shows that user <EMCLASS="emphasis">martin</EM> is running aFORTRAN compilation (<CODECLASS="literal">f77</CODE>).This process has<SPANCLASS="link">PID (<ACLASS="linkend"HREF="ch38_03.htm"TITLE="Managing Processes: Overall Concepts ">38.3</A>)</SPAN>12923 and is currently either running orrunable. User <EMCLASS="emphasis">chavez</EM>'s process (PID 16725), executing the program<EMCLASS="emphasis">g94</EM>, is also running or runable, though at a lowered priority.From this display, it's obvious who is using most system resources at thisinstant: <EMCLASS="emphasis">martin</EM> and <EMCLASS="emphasis">chavez</EM> have about 85% of the CPU and 73% ofthe memory between them. However, although it does display total CPU time,<EMCLASS="emphasis">ps</EM> does not average the <CODECLASS="literal">%CPU</CODE> or <CODECLASS="literal">%MEM</CODE> values over timein any way.<ACLASS="indexterm"NAME="AUTOID-42574"></A></P><TABLECLASS="table"><CAPTIONCLASS="table"><ACLASS="title"NAME="UPT-ART-1940-TAB-0">Table 38.1: ps Command Output Fields</A></CAPTION><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Column[3]</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Contents</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">USER (BSD)</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Username of process owner.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">UID (System V)</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Username of process owner.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">PID</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Process ID.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">%CPU</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Estimated fraction of CPU consumed (BSD).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">%MEM</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Estimated fraction of system memory consumed (BSD).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">SZ</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Virtual memory used in K (BSD) or pages (System V).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">RSS</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Real memory used (in same units as SZ).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">TT, TTY</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Terminal port associated with process.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">STAT (BSD),</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Current process state; one (or more under BSD) of:</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">    S (System V)</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">R:  Running or runnable.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">S:  Sleeping.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">I:  Idle (BSD). Intermediate state (System V).</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">T:  <SPANCLASS="link">Stopped (<ACLASS="linkend"HREF="ch12_08.htm"TITLE="Job Control in a Nutshell ">12.8</A>)</SPAN>.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"></TD><TD

⌨️ 快捷键说明

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