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

📄 unx19.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML>

<HEAD>

<TITLE>UNIX Unleashed unx19.htm</TITLE>

<LINK REL="ToC" HREF="index.htm">

<LINK REL="Next" HREF="unx20.htm">

<LINK REL="Previous" HREF="unx18.htm"></HEAD>

<BODY TEXT="#000000" LINK="#0000FF" VLINK="#800080" bgcolor=white>

<P><A HREF="unx18.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="unx20.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>

<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>

</P><UL>

<LI>

<A HREF="#I1">19 &#151; Administering Processes</A></LI>

<UL>

<UL>

<UL>

<UL>

<LI>

<A HREF="#I3">By Rachel and Robert Sartin</A></LI></UL></UL>

<LI>

<A HREF="#I4">Monitoring Processes&#151;ps and time</A></LI>

<UL>

<LI>

<A HREF="#I5">What Is ps?</A></LI>

<LI>

<A HREF="#I6">Introduction to SYSV ps Output</A></LI>

<LI>

<A HREF="#I7">Introduction to BSD ps Output</A></LI>

<LI>

<A HREF="#I8">Checking on Your Processes with ps</A></LI>

<UL>

<LI>

<A HREF="#I9">Everything You Own</A></LI>

<LI>

<A HREF="#I10">Specific Processes</A></LI>

<LI>

<A HREF="#I11">Specific Process Groups</A></LI>

<LI>

<A HREF="#I12">Specific Terminal</A></LI>

<LI>

<A HREF="#I13">Specific User</A></LI></UL>

<LI>

<A HREF="#I14">Checking on a Process with time</A></LI></UL>

<LI>

<A HREF="#I15">Background and Foreground Processes</A></LI>

<UL>

<LI>

<A HREF="#I16">Foreground Processing</A></LI>

<LI>

<A HREF="#I17">Where Is the Background and Why Should You Go There?</A></LI>

<LI>

<A HREF="#I18">Job Control</A></LI></UL>

<LI>

<A HREF="#I19">Signaling Processes</A></LI>

<LI>

<A HREF="#I20">Killing Processes</A></LI>

<UL>

<LI>

<A HREF="#I21">The kill Command</A></LI>

<LI>

<A HREF="#I22">Finding What to Kill Using ps</A></LI>

<UL>

<LI>

<A HREF="#I23">Determining Which Signal to Send</A></LI></UL>

<LI>

<A HREF="#I24">The dokill Script An Example</A></LI></UL>

<LI>

<A HREF="#I25">Logging Out with Background Processes</A></LI>

<UL>

<LI>

<A HREF="#I26">Using nohup</A></LI></UL>

<LI>

<A HREF="#I27">Prioritizing Processes</A></LI>

<UL>

<LI>

<A HREF="#I28">What Is a Priority?</A></LI>

<LI>

<A HREF="#I29">Being Nice</A></LI>

<LI>

<A HREF="#I30">Using renice on a Running Process</A></LI></UL>

<LI>

<A HREF="#I31">Job Control and Process Groups</A></LI>

<UL>

<LI>

<A HREF="#I32">Using the jobs Command</A></LI>

<LI>

<A HREF="#I33">Putting Jobs in the Foreground</A></LI>

<LI>

<A HREF="#I34">Suspending Process Groups</A></LI>

<LI>

<A HREF="#I35">Putting Jobs in the Background</A></LI>

<LI>

<A HREF="#I36">Using wait to Wait for Background Jobs</A></LI>

<LI>

<A HREF="#I37">Using csh notify to Learn About Changes Sooner</A></LI></UL>

<LI>

<A HREF="#I38">My System Is Slow&#151;Performance Tuning</A></LI>

<UL>

<LI>

<A HREF="#I39">Monitoring the System with ps</A></LI>

<LI>

<A HREF="#I40">Monitoring the System with sar</A></LI></UL>

<LI>

<A HREF="#I41">Summary</A></LI></UL></UL></UL>



<H1 ALIGN="CENTER">

<CENTER><A ID="I1" NAME="I1">

<BR>

<FONT SIZE=5><A ID="I2" NAME="I2"></A><B>19 &#151; Administering Processes</B>

<BR></FONT></A></CENTER></H1>

<H5 ALIGN="CENTER">

<CENTER><A ID="I3" NAME="I3">

<FONT SIZE=3><B>By Rachel and Robert Sartin</B>

<BR></FONT></A></CENTER></H5>

<P>You use processes on UNIX every time you want to get something done. Each command (that isn't built into your shell) you run will start one or more new processes to perform your desired task. To get the most benefit out of your UNIX machine you need to 

learn how to monitor and control the processes that are running on it. You will need to know how to make large, but not time-critical, tasks take less of your CPU time. You will need to learn how to shut down programs that have gone astray. You will need 
to learn how to improve the performance of your machine.

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I4" NAME="I4">

<FONT SIZE=4><B>Monitoring Processes&#151;</B><B><I>ps</I></B><B> and </B><B><I>time</I></B>

<BR></FONT></A></CENTER></H3>

<P>The first step in controlling processes in UNIX is to learn how to monitor them. By using the process-monitoring commands in UNIX, you will be able to find what programs are using your CPU time, find jobs that are not completing, and generally explore 
what is happening to your machine.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I5" NAME="I5">

<FONT SIZE=3><B>What Is </B><B><I>ps</I></B><B>?</B>

<BR></FONT></A></CENTER></H4>

<P>The first command you should learn about is the ps command, which prints out the process status for some or all of the processes running on your UNIX machine.

<BR></P>

<P>There are two distinctly different versions of ps: the SYSV version and the BSD version. Your machine might have either one or both of the ps commands. If you are running on a machine that is mostly based on Berkeley UNIX, try looking in /usr/5bin for 
the SYSV version of ps. If you are running on a machine that is mostly based on System V UNIX, try looking in /usr/ucb for the BSD version of ps. Check your manuals and the output of your ps program to figure out which one you have. You may want to read 
the introductions to both SYSV and BSD ps output since some systems either combine features of both (for example, AIX) or have both versions (for example, Solaris 2.3, which has SYSV /usr/bin/ps and BSD /usr/ucb/ps).

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I6" NAME="I6">

<FONT SIZE=3><B>Introduction to SYSV </B><B><I>ps</I></B><B> Output</B>

<BR></FONT></A></CENTER></H4>

<P>If you are using SYSV, you should read this section to learn about the meaning of the various fields output by ps. 

<BR></P>

<P>Look at what happens when you enter ps:

<BR></P>

<PRE>$ ps

   PID TTY      TIME COMD

  1400 pts/5    0:01 sh

  1405 pts/5    0:00 ps

$ </PRE>

<P>The PID field gives you the process identifier, which uniquely identifies a particular process. The TTY fields tell what terminal the process is using. It will have ? if the process has no controlling terminal. It may say console if the process is on 
the system console. The terminal listed may be a pseudo terminal, which is how UNIX handles terminal-like connections from a GUI or over the network. Pseudo terminal names often begin with pt (or just p, if your system uses very short names). The TIME 
field tells how much CPU time the process has used. The COMD field (sometimes labelled CMD or COMMAND) tells what command the process is running.

<BR></P>

<P>Now look at what happens when you enter ps -f:

<BR></P>

<PRE>$ ps -f

     UID   PID  PPID  C    STIME TTY      TIME COMD

  sartin  1400  1398 80 18:31:32 pts/5    0:01 -sh

  sartin  1406  1400 25 18:34:33 pts/5    0:00 ps -f

$</PRE>

<P>The UID field tells which user ID owns the process. Your login name should appear here. The PPID field tells the process identifier of the parent of the process; notice that the PPID of ps -f is the same as the PID of -sh. The C field is 
process-utilization information used by the scheduler. The STIME is the time the process started.

<BR></P>

<P>Next, look at what happens when you enter ps -l:

<BR></P>

<PRE>$ ps -l

 F S   UID   PID  PPID  C PRI NI     ADDR     SZ    WCHAN TTY      TIME COMD

 8 S   343  1400  1398 80   1 20 fc315000    125 fc491870 pts/5    0:01 sh

 8 O   343  1407  1400 11   1 20 fc491800    114          pts/5    0:00 ps

$</PRE>

<P>Note that the UID is printed out numerically this time. The PRI field is the priority of the process; a lower number means more priority to the scheduler. The NI field is the nice value. See the section &quot;Prioritizing Processes&quot; for more 
information on the scheduler and nice values. The SZ field shows the process size. The WCHAN field tells what event, if any, the process is waiting for. Interpretation of the WCHAN field is specific to your system.

<BR></P>

<P>On some SYSV systems with real-time scheduling additions, you may see output such as the following if you enter ps -c:

<BR></P>

<PRE>$ ps -c

   PID  CLS PRI TTY      TIME COMD

  1400   TS  62 pts/5    0:01 sh

  1409   TS  62 pts/5    0:00 ps

$ </PRE>

<P>The CLS field tells the scheduling class of the process; TS means time sharing and is what you will usually see. You may also see SYS for system processes and RT for real-time processes.

<BR></P>

<P>On some SYSV systems running the Fair Share Scheduler, you may see output such as the following if you enter ps -f:

<BR></P>

<PRE>$ ps -f

     UID    FSID   PID  PPID  C    STIME TTY      TIME COMMAND

  sartin rddiver 18735 18734  1  Mar 12  ttys0    0:01 -ksh

  sartin rddiver 19021 18735  1 18:47:37 ttys0    0:01 xdivesim

  sartin rddiver 19037 18735  4 18:52:58 ttys0    0:00 ps -f

    root default 18734   136  0  Mar 12  ttys0    0:01 rlogind

$ </PRE>

<P>The extra FSID field tells the fair share group for the process.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I7" NAME="I7">

<FONT SIZE=3><B>Introduction to BSD </B><B><I>ps</I></B><B> Output</B>

<BR></FONT></A></CENTER></H4>

<P>If you are using BSD, you should read this section to learn about the meaning of the various fields output by ps. 

<BR></P>

<P>Look at what happens when you enter ps:

<BR></P>

<PRE>$ ps

  PID TT STAT  TIME COMMAND

22711 c0 T     0:00 rlogin brat

22712 c0 T     0:00 rlogin brat

23121 c0 R     0:00 ps

$ </PRE>

<P>The PID field gives you the process identifier, which uniquely identifies a particular process. The TT fields tell what terminal the process is using. It will have ? if the process has no controlling terminal. It may say co if the process is on the 
system console. The terminal listed may be a pseudo terminal. The STAT field shows the process state. Check your manual entry for ps to learn more about state. The TIME field tells how much CPU time the process has used. The COMMAND field tells what 
command the process is running. Normally, the COMMAND field lists the command arguments stored in the process itself. On some systems, these arguments can be overwritten by the process. If you use the c option, the real command name will be given, but not 

⌨️ 快捷键说明

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