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

📄 0302-0304.html

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


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Basic System Administration</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=0672311623 //-->

<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->

<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=20 //-->

<!-- PAGES=0291-0312 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->











<P><CENTER>

<a href="0299-0301.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0305-0307.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-302"><P>Page 302</P></A>





<!-- CODE //-->

<PRE>

# free

             total       used       free     shared    buffers     cached

Mem:         30892      28004       2888      14132       3104      10444

-/+ buffers:            14456      16436

Swap:        34268       7964      26304

</PRE>

<!-- END CODE //-->



<P>This shows a 32MB system with 34MB swap space. Notice that nearly all the

system memory is being used, and nearly 8MB of swap space has been used.

</P>



<P>By default, the free command displays memory in kilobytes, or 1024-byte notation. You

can use the -b option to display your memory in bytes, or the

-m option to display memory in megabytes. You can also use the

free command to constantly monitor how much memory is being used through the

-s command. This is handy as a real-time monitor if you

specify a .01-second update and run the free command in a terminal window under X11.

</P>



<H4><A NAME="ch20_ 12">

Virtual Memory Reporting with the vmstat Command

</A></H4>



<P>The vmstat is a general-purpose monitoring program, which offers real-time display of

not only memory usage, virtual memory statistics, but disk activity, system usage, and

central processing unit (CPU) activity. If you call

vmstat without any command-line options, you'll get a one-time

snapshot, for example:

</P>



<!-- CODE //-->

<PRE>

# vmstat

 procs                  memory    swap        io    system         cpu

 r b w  swpd  free  buff cache  si  so   bi   bo   in   cs  us  sy  id

 0 0 0  7468  1060  4288 10552   1   1   10    1  134   68   3   2  96

</PRE>

<!-- END CODE //-->



<P>If you specify a time interval in seconds on the

vmstat command line, you'll get a continuously scrolling report. Having a constant display of what is going on with your computer can

help you if you're trying to find out why your computer suddenly slows down, or why

there's a lot of disk activity.

</P>



<H4><A NAME="ch20_ 13">

Viewing Your Shell's &quot;Ulimit&quot;ations

</A></H4>



<P>You've already seen how you can limit the size of core dump files previously in this

hour. There are other settings you can set in your shell. If you're using the

bash or pdksh (ksh) shell, you can use the ulimit command's

-a option to print your current settings, for example:

</P>

<!-- CODE //-->

<PRE>

# ulimit -a

core file size (blocks)  1000000

data seg size (kbytes)   unlimited

file size (blocks)       unlimited

max memory size (kbytes) unlimited

stack size (kbytes)      8192

cpu time (seconds)       unlimited

max user processes       256

pipe size (512 bytes)    8

open files               256

virtual memory (kbytes)  2105343

</PRE>

<!-- END CODE //-->



<P>If you're using the tcsh or csh shell, you can use the

limit command to list the current settings:

</P>





<A NAME="PAGENUM-303"><P>Page 303</P></A>





<!-- CODE //-->

<PRE>

$ limit

cputime         unlimited

filesize        unlimited

datasize        unlimited

stacksize       8192 kbytes

coredumpsize    1000000 kbytes

memoryuse       unlimited

descriptors     256

memorylocked    unlimited

maxproc         256

</PRE>

<!-- END CODE //-->



<P>These limits are different from limits for the root operator. The limits shown in

this example are known as soft limits. To view the shell's hard limits, log in as the root

operator, and use the -a limit option (use -Ha for bash or ksh's

ulimit command), for example:

</P>



<!-- CODE //-->

<PRE>

$ su

Password:

# limit -h

cputime         unlimited

filesize        unlimited

datasize        unlimited

stacksize       8192 kbytes

coredumpsize    unlimited

memoryuse       unlimited

descriptors     256

memorylocked    unlimited

maxproc         256

</PRE>

<!-- END CODE //-->



<P>As you can see, viewing the limits as the root operator in the tcsh shell shows a

much different situation. This is another good reason not to run as the root operator! As

a sysadmin, you can use these settings to limit the amount of memory or number of

processes available to each user. This is extremely handy if you have a number of people working

on your computer at the same time, and you want to conserve system memory. For

using Linux on a standalone computer under your normal login and working conditions,

you'll find the default limits quite reasonable.

</P>



<H4><A NAME="ch20_ 14">

Reclaiming Memory with the kill Command

</A></H4>



<P>As a desperate measure if you need to quickly reclaim memory, you can stop

running programs by using the kill command. In order to kill a specific program, you should

use the ps command to list current running processes, and then stop any or all of them with

the kill command. By default, the ps command lists processes you own and which you can

kill, for example:

</P>





<!-- CODE //-->

<PRE>

# ps

  PID TTY STAT  TIME COMMAND

  367  p0 S    0:00 bash

  581  p0 S    0:01 rxvt

  582  p1 S    0:00 (bash)

  747  p0 S    0:00 (applix)

  809  p0 S    0:18 netscape index.html

</PRE>

<!-- END CODE //-->



<A NAME="PAGENUM-304"><P>Page 304</P></A>





<!-- CODE SNIP //-->

<PRE>

  810  p0 S    0:00 (dns helper)

  945  p0 R    0:00 ps

</PRE>

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



<P>The ps command will list the currently running programs and the program's

process number, or PID. You can use this information to kill a process with

</P>



<!-- CODE SNIP //-->

<PRE>

# kill -9 809

</PRE>

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



<P>However, if you need to reclaim memory efficiently, you should use the

ps command's -m option, which also lists the memory usage of each process, for example:

</P>



<!-- CODE //-->

<PRE>

# ps -m

  PID TTY MAJFLT MINFLT  TRS   DRS  SIZE  SWAP   RSS  SHRD   LIB  DT COMMAND

  747  p0      0      3   16   208   364   140   224   224     0   0 (applix)

  582  p1    151    274  124   184   436   128   308   268     0  10 (bash)

  959  p0     89     20   28   376   404     0   404   320     0  21 ps -m

  367  p0    305    826  220   316   600    64   536   428     0  27 bash

  810  p0    313     38  164   696   968   108   860   596     0  47 (dns helpe

  581  p0    212    508   28   960  1280   292   988   304     0 171 rxvt

  809  p0   2615   1205 3900  3692  8684  1092  7592  4644     0 699 netscape

</PRE>

<!-- END CODE //-->



<P>By using this information, you can see that if you want to reclaim the most memory,

you should stop the Netscape Web browser, as it is using nearly 9MB of system

memory. Although you wouldn't normally use the

kill command to stop programs, the kill command can be helpful to stop runaway, or nonresponsive, programs. The

kill command works by sending a signal to the Linux kernel, along with the PID, so the kernel can act on

the process. There are various signals you can use, although, as I've pointed out, the -9,

or SIGKILL option is the most abrupt and drastic. You can see a list of different signals by

using the kill command's -l option, for example:

</P>



<!-- CODE //-->

<PRE>

# kill -l

 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL

 5) SIGTRAP      6) SIGIOT       7) SIGBUS       8) SIGFPE

 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2

13) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD

18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN

22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ

26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO

30) SIGPWR

</PRE>

<!-- END CODE //-->



<P>For more details on these signals, and the kill command, see its manual page.

</P>



<P>The ps command has nearly two dozen command-line options, and you can also list

all running processes. See the ps manual page for more information. You can also use the

top command, discussed next, to find and kill processes.

</P>



<H3><A NAME="ch20_ 15">

Getting System Load Information with the top and

xload Commands

</A></H3>



<P>The top command, found under the /usr/bin directory, is a system monitor that

displays

</P>



<P><CENTER>

<a href="0299-0301.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0305-0307.html">Next</A>

</CENTER></P>











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

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

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