linux command Application Analysis

1. Description

Application of problem analysis and there are a lot of command, generally a combination of the use, under today focuses on:

(1) top command, view real-time server resource usage, Explorer-like under windows;

(2) tail command to view the log in real-time refresh command.

2. top command

top command is commonly used under Linux performance analysis tools, it can display real-time system resource usage status of each process.

2.1 Command Usage

top   //默认每隔5秒,显示所有进程的资源占用情况
top -d 2  //每隔2秒,显示所有进程的资源占用情况
top -c  //每隔5秒,显示所有进程的资源占用情况,-c重点是能看到命令行参数名称(比如java项目,不加-c的话只有java,增加-c的话,能看到具体执行参数,i'm 软件老王)

2.2 top the displayed information

(1) The first line is not to say, mean nothing;

(2) the second line shows the process of summary information, including:

total   进程总数
running 正在运行的进程数
sleeping 睡眠的进程数
stopped 停止的进程数
zombie 僵尸进程数

(3) the third line, shows the use of cpu, wherein:

0.2% us 用户空间占用CPU百分比
0.2% sy 内核空间占用CPU百分比
0.0% ni 用户进程空间内改变过优先级的进程占用CPU百分比
99.6% id 空闲CPU百分比
0.0% wa 等待输入输出的CPU时间百分比
0.0%hi:硬件CPU中断占用百分比
0.0%si:软中断占用百分比
0.0%st:虚拟机占用百分比

Note: You can press "1", the third row can be expanded (for example, 4 cpu launched four lines) in the top command to see each cpu accounting situation.

(4) The fourth and fifth lines, shows the memory usage, wherein:

Mem:
total    物理内存总量
free    空闲内存总量
used    使用的物理内存总量
buffer    用作内核缓存的内存量

Swap: 
total    交换区总量
free    空闲交换区总量
used    使用的交换区总量
avail Mem 有效内存

(5) the sixth row, shows the specific users and processes cpu and memory use cases, including:

PID     进程id
USER   Real user name
PR      优先级
NI      nice值。负值表示高优先级,正值表示低优先级
VIRT    进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES     进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR     共享内存大小,单位kb
S       进程状态(D=不可中断的睡眠状态,R=运行,S=睡眠,T=跟踪/停止,Z=僵尸进程)
%CPU    上次更新到现在的CPU时间占用百分比
%MEM    进程使用的物理内存百分比
TIME    进程使用的CPU时间总计,单位秒
COMMAND 命令名/命令行

Special Note: Note that the% cpu cpu third row with a sixth row of a difference.

Which cpu third line (%) represents the average of all the user processes throughout the cpu, because each occupies a percentage of the core, so by comparison with a reference to count the average sense, but the sixth line of the display% CPU is a nuclear process takes a percentage, rather than the percentage of the total cpu (4-core), and sometimes may be greater than 100, it is because the process enables multi-threaded occupies multiple core (i'm Pharaoh software), so sometimes we look at the time worth more than 100%, but will not exceed the total number of cores * 100.

3. tail view real-time log command

3.1 real-time view the log file

(1) Description: When you need to locate or view the problem, the need for real-time tracking logs.

(2) Command Usage

tail -f test.log

(3) tail command parsing

-f  循环读取
-q  不显示处理信息
-v  显示详细的处理信息
-c<数目> 显示的字节数
-n<行数>  显示行数
–pid=PID 与-f合用,表示在进程ID,PID死掉之后结束. 
-q, –quiet, –silent 从不输出给出文件名的首部 
-s, –sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒 

3.2 Empty file

(1) Description: Sometimes the log file contents or a little more, is not convenient to view, needs to be emptied, you can use the copy and then deleted, but a bit of trouble, you can use echo directly emptied.

(2) Command Usage

echo > nohup.out

Intermediate spaces can not be

(3) echo usage examples

a. printed to the console

echo I am 软件老王 
echo "I am 软件老王"

b. Print to file

touch test.txt        
echo 软件老王 > test.txt

c. additional content to file

echo 是帅哥 >> test.txt

I'm "Software Pharaoh," I felt that if I may, to focus the next chant, subsequent updates seconds to know! Welcome forum, No. namesake public message exchange!

Guess you like

Origin www.cnblogs.com/ruanjianlaowang/p/11357459.html