Linux command to view system resources

view of the process

[root@linux ~]# ps aux        <== View all process data of the system

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.0 0.1 1740 540 ? S Jul25 0:01 init [3]

root 2 0.0 0.0 0 0 ? SN Jul25 0:00 [ksoftirqd/0]

root 3 0.0 0.0 0 0 ? S< Jul25 0:00 [events/0]

.....omitting the middle.....

root 5881 0.0 0.3 5212 1204 pts / 0 S 10:22 0:00 su

root 5882 0.0 0.3 5396 1524 pts/0 S 10:22 0:00 bash

root 6142 0.0 0.2 4488 916 pts/0 R+ 11:45 0:00 ps aux

 

The meaning of each field is:

• USER: Which user account does this process belong to?

• PID: The process number.

• %CPU: The percentage of CPU resources used by the process;

• %MEM: the percentage of physical memory occupied by the process;

• VSZ: The amount of virtual memory (Kbytes) used by the process

• RSS: The fixed amount of memory (Kbytes) occupied by the process

• TTY: The process is running on the terminal, if it has nothing to do with the terminal, it will display ?. In addition, tty1-tty6 are the registrant programs on the local machine. If it is pts/0, etc., it will be indicated as A program that connects to a host computer over a network.

• STAT: the current state of the program, the main states are:

o R : the program is currently running, or can be run;

o S : The program is currently sleeping (it can be said to be in an idle state!), but can be woken up by some signals.

o T :该程序目前正在侦测或者是停止了;

o Z :该程序应该已经终止,但是其父程序却无法正常的终止他,造成 zombie (疆尸) 程序的状态

• START:该 process 被触发启动的时间;

• TIME :该 process 实际使用 CPU 运作的时间。

• COMMAND:该进程的实际命令

 

[root@linux ~]# ps -l      <==仅查看自己的bash相关进程

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

0 S 0 5881 5654 0 76 0 - 1303 wait pts/0 00:00:00 su

4 S 0 5882 5881 0 75 0 - 1349 wait pts/0 00:00:00 bash

4 R 0 6037 5882 0 76 0 - 1111 - pts/0 00:00:00 ps

# 上面这个信息其实很多喔!各相关信息的意义为:

# F 代表这个程序的旗标 (flag), 4 代表使用者为 super user;

# S 代表这个程序的状态 (STAT),关于各 STAT 的意义将在内文介绍;

# PID 没问题吧!?就是这个程序的 ID 啊!底下的 PPID 则上父程序的 ID;

# C CPU 使用的资源百分比

# PRI 这个是 Priority (优先执行序) 的缩写,详细后面介绍;

# NI 这个是 Nice 值,在下一小节我们会持续介绍。

# ADDR 这个是 kernel function,指出该程序在内存的那个部分。如果是个 running

的程序,一般就是『 - 』的啦!

# SZ 使用掉的内存大小;

# WCHAN 目前这个程序是否正在运作当中,若为 - 表示正在运作;

# TTY 登入者的终端机位置,若为远程登录则使用动态终端接口(pts/n)

# TIME 使用掉的 CPU 时间。

# CMD 所下达的指令为何!?

 

范例:找出与 cron 与 syslog 这两个服务有关的 PID 号码?

[root@linux ~]# ps aux | egrep '(cron|syslog)'

root 1539 0.0 0.1 1616 616 ? Ss Jul25 0:03 syslogd -m 0

root 1676 0.0 0.2 4544 1128 ? Ss Jul25 0:00 crond

root 6157 0.0 0.1 3764 664 pts/0 R+ 12:10 0:00 egrep (cron|syslog)

 

iostat  命令为你提供系统的不同信息,包括CPU时间的统计、I/O设备、分区和网络文件系统(NFS)。

[root@AY1407070046165819beZ ~]# iostat
Linux 2.6.32-431.17.1.el6.x86_64 (AY1407070046165819beZ)  

01/16/2017      _x86_64_  (1 CPU)

avg-cpu:  %user   %nice   %system   %iowait  %steal   %idle
       0.73    0.00    0.20    0.93    0.00    98.14

Device:   tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn xvda      

       3.15   45.60       17.01     1773055956  661424568

xvdb     0.00   0.00        0.00       1392     0

 


# 例如,如果 %idle 低,可以确定系统一直很忙碌。高 %iowait 表明磁盘出现问题。如果 %system 或 %nice 比 %user 高,则表明系统失衡且级别高的进程阻止普通进程的运行。

 

系统资源的查看

[root@linux ~]# free [-b|-k|-m|-g] [-t]

参数:

-b :直接输入 free 时,显示的单位是 Kbytes,我们可以使用 b(bytes), m(Mbytes)

k(Kbytes), 及 g(Gbytes) 来显示单位喔!

-t :在输出的最终结果,显示物理内存与 swap 的总量。

范例:

范例一:显示目前系统的内存容量

[root@linux ~]# free -m

total used free shared buffers cached

Mem: 376 366 10 0 129 94

-/+ buffers/cache: 141 235

Swap: 996 0 995

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326363741&siteId=291194637