Top监控工具在Tru64UNIX的安装与使用
发表于:2007-07-04来源:作者:点击数:
标签:
前言: Top命令是一个功能十分强大的监控系统的工具,它提供运行在系统上的与CPU关系最密切的进程列表,以及许多意义的统计值,例如负载平均、进程数量、使用的存储器和页面空间数量。它将显示系统中CPU最“敏感”的任务列表,该命令可以按CPU使用、内存使用
前言: Top命令是一个功能十分强大的监控系统的工具,它提供运行在系统上的与CPU关系最密切的进程列表,以及许多意义的统计值,例如负载平均、进程数量、使用的存储器和页面空间数量。它将显示系统中CPU最“敏感”的任务列表,该命令可以按CPU使用、内存使用和执行时间对任务进行排序,而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定。
Top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态。如果在前台执行该命令,它将独占前台,直到用户终止该程序为止。比较准确的说,Top命令提供了实时的对系统处理器的状态监视。Tru 64 UNIX 4.0f同样也支持这个命令,下面我将详细介绍如何把这个命令安装
一、 安装前的准备 1. 以root身份创建临时目录
#mkdir /freeware
#chown root /freeware
#chgrp bin /freeware
#cd /freeware
#mkdir bin
#mkdir man
#cd man
#mkdir man1
/freeware/bin为命令编译的命令目录;/freeware/man/man1为man命令来学习Top命令存放的信息的位置。
2.命令网址
http://www.funet.fi/pub/unix/tools/top/top-3.5beta9.tar.gz 将文件Top-3.5beta9.tar.gz
下载并存放在/freeware下,这是一个压缩的tar文件,为此我们还要解压缩、解tar:
#cd /freeware
#gunzip Top-3.5beta9.tar.gz
#tar -xvf Top-3.5beta9.tar.gz
这样,在/freeware目录下,产生一个目录为:Top-3.5beta9
#chmod -R 755 Top-3.5beta9
二、安装过程 #cd /freeware/Top-3.5beta9
# ./Configure
Configuration for Top, version 3.5
One moment....
Reading configuration from last time...
You will be asked a series of questions. Each question will
have a default answer enclosed in brackets, such as "[5.0]". In most cases, the default answer will work well. To use that value, merely press return.
The following machine-dependent modules are available:
386bsd For a 386BSD system
aix32 POWER and POWER2 running AIX 3.2.5.0
aix41 PowerPC running AIX 4.1.2.0
aux3 a Mac running A/UX version 3.x
bsd386 For a BSD/386 system
bsd43 any generic 4.3BSD system
bsd44 For a 4.4BSD system
bsd44a For a pre-release 4.4BSD system
bsdos2 For a BSD/OS 2.X system (based on the 4.4BSD Lite
system)
convex any C2XX running Convex OS 11.X.
dcosx For Pyramid DC/OSX
decosf1 DEC Alpha AXP running OSF/1 or Digital Unix 4.0.
dgux for DG AViiON with DG/UX 5.4+
dynix any Sequent Running Dynix 3.0.x
dynix32 any Sequent Running Dynix 3.2.x
freebsd20 For a FreeBSD-2.0 (4.4BSD) system
ftx For FTX based System V Release 4
hpux10 any hp9000 running hpux version 10.x
hpux7 any hp9000 running hpux version 7 or earlier
hpux8 any hp9000 running hpux version 8 (may work with 9)
hpux9 any hp9000 running hpux version 9
irix5 any uniprocessor, 32 bit SGI machine running IRIX 5.3
irix62 any uniprocessor, SGI machine running IRIX 6.2
linux Linux 1.2.x, 1.3.x, using the /proc filesystem
mtxinu any VAX Running Mt. Xinu MORE/bsd
ncr3000 For NCR 3000 series systems Release 2.00.02 and above
netbsd08 For a NetBSD system
netbsd10 For a NetBSD-1.0 (4.4BSD) system
netbsd132 For a NetBSD-1.3.2 (4.4BSD) system
next32 any m68k or intel NEXTSTEP v3.x system
next40 any hppa or sparc NEXTSTEP v3.3 system
osmp41a any Solbourne running OS/MP 4.1A
sco SCO UNIX
sco5 SCO UNIX OpenServer5
sunos4 any Sun running SunOS version 4.x
sunos4mp any multi-processor Sun running SunOS versions 4.1.2
or later
sunos5 Any Sun running SunOS 5.x (Solaris 2.x)
svr4 Intel based System V Release 4
svr42 For Intel based System V Release 4.2 (DESTINY)
ultrix4 any DEC running ULTRIX V4.2 or later
umax Encore Multimax running any release of UMAX 4.3
utek Tektronix 43xx running UTek 4.1
What module is appropriate for this machine? [decosf1]:
This is the machine-dependent module for DEC OSF/1
It is known to work on OSF/1 1.2, 1.3, 2.0-T3, 3.0, and Digital Unix V4.0
WARNING: if you use optimization with the standard "cc" compiler
That comes with V3.0 the resulting executable may core dump.
If this happens, recompile without optimization.
Is this what you want to use? [yes]:
First we need to find out a little bit about the executables needed to compile top.
What is the full path name for the Bourne shell [/bin/sh]:
Please supply the name of the appropriate command. It need not be a full path name, but the named command does need to existsomewhere on the current path.
AWK Interpreter [awk]:
C Compiler [cc]:
The installer command needs to understand Berkeley-esque arguments:
"-o" for owner, "-g" for group, and "-m" for mode. A shell script called "install" is distributed with top and is suitable for use by top. You can specify a different program here if you like, or use the shell script (the default).
Installer [./install]:
What other options should be used with the cc command (use "none" to specify no options)?
Compiler options [-O]:
Now you need to answer some questions concerning the configuration of top itself.
The space command forces an immediate update. Sometimes, on loaded systems, this update will take a significant period of time (because all the output is buffered). So, if the short-term load average is above "LoadMax", then top will put the cursor home immediately after the space is pressed before the next update is attempted. This serves as a visual acknowledgement of the command. "LoadMax" should always be specified as a floating point number.
LoadMax [5.0]:
"Default TOPN" is the default number of processes to show. This is the number that will be used when the user does not specify the number of processes to show. If you want "all" (or infinity) as the default, use the value "-1".
Default TOPN [15]:
"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity and the output is a dumb terminal. If we didn't do this, then installations who use a default TOPN of Infinity will get every process in the system when running top on a dumb terminal (or redirected to a file).
Note that Nominal_TOPN is a default: it can still be overridden on the command line, even with the value "infinity".
Nominal TOPN [18]:
Default Delay is the default number of seconds to wait between screen updates.
Default Delay [5]:
It looks like you have a passwd file that can be accessed at random.
Do you want top to take advantage of this? [yes]:
Compiling prime.c
I found 82 entries in your passwd file. Top hashes the username To uid mappings as it goes along and it needs a good guess on the size of that hash table. This number should be the next highest prime number after 164.
I have calculated that to be 167.
Enter the hash table size [167]:
Uh oh! I see /proc out there. Some new Unix variants provide The /proc file system as a mechanism to get to a process's address space.
This directory is typically only accessible by root. However, There are a few systems (such as DG/UX) on which this directory exists, but isn't used. I'm going to assume that top needs to run setuid to root, but you should double check and use mode 2755 (set group id) if top doesn't really need root access. If you are running SunOS 5.0 -
SunOS 5.5.1 then you will need to install top setuid root (owner root And mode 4711). In SunOS 5.6 top only requires set-gid sys permissions.
Tell me how to set the following when top is installed:
Owner [root]:
Group owner [bin]:
Mode [4711]:
Install the executable in this directory [/freeware/bin]:
Install the manual page in this directory [/freeware/man/man1]:
Install the manual page with this extension [l]:
Install the manual page as 'man' or 'catman' [man]:
We are done with the questions.
Saving configuration...
#define SIGKILL 9 /* kill (cannot be caught or ignored) */
Building Makefile...
Building top.local.h...
Building top.1...
Doing a "make clean".
rm -f *.o top core core.* sigdesc.h
To create the executable, type "make".
To install the executable, type "make install".
上面参数的填写主要根据自己的情况来决定,仔细看呀。
# make
cc -DHAVE_GETOPT -O -c Top.c
awk -f sigconv.awk /usr/include/signal.h >sigdesc.h
cc -DHAVE_GETOPT -O -c commands.c
cc -DHAVE_GETOPT -O -c display.c
cc -DHAVE_GETOPT -O -c screen.c
cc -DHAVE_GETOPT -O -c username.c
cc -DHAVE_GETOPT -O -c utils.c
cc -DHAVE_GETOPT -O -c version.c
cc -DHAVE_GETOPT -O -c getopt.c
cc "-DOSREV=V40" -DHAVE_GETOPT -O -c machine.c
cc: Warning: machine.c, line 551: The scalar variable "where" is
fetched but not initialized. (uninit1)
if (where == 1) {--------^
rm -f Top
cc -o Top Top.o commands.o display.o screen.o username.o
utils.o version.o geto
pt.o machine.o -ltermcap -lm -lmld -lmach
# make install
•/install -o root -m 4711 -g bin Top /freeware/bin
•/install Top.1 /freeware/man/man1/Top.l
整个过程执行完,在/freeware/bin下形成两个文件Top、Top.l,由于man命令的学习信息格式为:Top.1.gz,所以我们还要做如下工作:
#mv /freeware/man/man1/Top.l /freeware/man/man1/Top.1
#gzip /freeware/man/man1/Top.1为Top.1.gz
#mv /freeware/bin/Top /bin
#mv /freeware/man/man1/Top.l.gz /usr/share/man/man1
这样,整个安装过程就结束了。
三、 Top在Tru 64上的输出 格式
javascript:window.open(this.src);" style="CURSOR: pointer" onload="return imgzoom(this,550)"> 第一行的项目依次为平均负载、当前时间。第二行为进程情况,依次为进程总数、运行进程数、等待进程数、休眠进程数空闲进程数。第三行为CPU状态,依次为用户占用、优先进程占用、系统占用、闲置进程占用。第四行为内存状态、交换状态,依次为已用内存、平均可用内存、已用交换区容量、可用交换区容量。然后下面就是和ps相仿的各进程情况列表了。"
我们可以利用Top命令来查看最耗CPU资源的进程。Top命令还会根据进程占用CPU资源的多少而动态改变。总的来说,Top命令的功能强于ps,但需要长久占用前台,所以用户应该根据自己的情况来使用这个命令。
四、 Top命令的语法格式 Top [ -SbiInquv ] [ -dcount ] [ -stime ] [ -ofield ] [ -Uusername ] [ number ]
使用权限:所有使用者
相关命令:Kill ,ps,stty,mem,renice
补充说明:
执行Top指令可显示当前正在系统中执行的程序,并通过它所提供的交互式截面,用功能键加以管理。
相关参数说明:
Top 显示系统程序的执行状态,并指定每间隔时间刷新一次信息
-s 使用累计模式显示系统程序的执行状态
-b 使用“batch”模式显示系统的执行状态,此时所有的功能键均没有任何作用
-i 使用“interactive”模式显示系统的执行状态
-I 显示系统程序的执行状态,不显示空闲进程及已经成为僵尸的进程
-n 使用“no-interactive” 模式显示系统的执行状态
-q 仅在root下用,重置Top优先级到-20
-u 不显示用户UID
-v 显示版本号
-dcount 屏幕刷新count次后,Top命令自己也退出
-stime 设置屏幕刷新的时间间隔time,缺省为5秒
-ofield 在指定的字段中,排序进程显示域
-Uusername 仅仅显示username拥有的进程
操作命令:
d 输入刷新数
u 显示指定用户的程序执行状态
o 改变显示字段的顺序
n 或 # 设置最多要显示几个程序。若设为0,则不作任何限制
空格键 立即更新显示中的数据
h或 ? 显示在线说明
Ctrl+ L 重新显示画面
q 结束程序
s 设置屏幕刷新的时间间隔,单位为秒
k 中止执行中的程序,相当于命令:kill
r 调整执行程序的优先权
e 显示系统的错误列表
I或 i 切换是否显示闲置中及成为僵尸的程序
从上面的介绍中可以看到,Top命令是一个功能十分强大的监控系统的工具,尤其对于系统管理员而言更是如此。一般的用户可能会觉得ps命令其实就够用了,但是Top命令的强劲功能确实提供了不少方便。熟悉并灵活应用Top的 命令,可以大大方便系统管理人员和用户,并收到事半功倍之。
原文转自:http://www.ltesting.net