设为首页 收藏本站
查看: 256|回复: 0

[经验分享] linux 系统上的进程查看管理工具之htop/dstat/top/ps命令详解

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2016-3-25 08:26:51 | 显示全部楼层 |阅读模式
一、ps命令详解:
ps 加选项参数

ps a 显示与终端相关的内容信息,例如:

[iyunv@server cx]# ps a
  PID TTY      STAT   TIME COMMAND
  2396 tty3     Ss+    0:00 /sbin/mingetty /dev/tty3
  2399 tty4     Ss+    0:00 /sbin/mingetty /dev/tty4
  2401 tty5     Ss+    0:00 /sbin/mingetty /dev/tty5
  2404 tty6     Ss+    0:00 /sbin/mingetty /dev/tty6
  2472 tty1     Ss+    0:02 /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/
  5095 pts/0    Ss     0:02 -bash
  6285 tty2     Ss+    0:00 -bash
  8612 pts/0    R+     0:00 ps a
ps  x  显示与终端无关的内容信息,例如:


[iyunv@server cx]# ps x
    PID TTY      STAT   TIME COMMAND
     1 ?        Ss     0:02 /sbin/init
     2 ?        S      0:00 [kthreadd]
     3 ?        S      0:00 [migration/0]
     4 ?        S      0:00 [ksoftirqd/0]
     5 ?        S      0:00 [stopper/0]
     6 ?        S      0:00 [watchdog/0]
     7 ?        S      0:00 [migration/1]
     8 ?        S      0:00 [stopper/1]
     9 ?        S      0:00 [ksoftirqd/1]
    10 ?        S      0:00 [watchdog/1]
ps u 以用户为中心组织进程状态信息显示;
[iyunv@server cx]# ps u
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       2396  0.0  0.0   4064   552 tty3     Ss+  08:05   0:00 /sbin/mingetty /dev/tty3
root       2399  0.0  0.0   4064   552 tty4     Ss+  08:05   0:00 /sbin/mingetty /dev/tty4
root       2401  0.0  0.0   4064   552 tty5     Ss+  08:05   0:00 /sbin/mingetty /dev/tty5
root       2404  0.0  0.0   4064   552 tty6     Ss+  08:05   0:00 /sbin/mingetty /dev/tty6

[iyunv@server cx]# ps aux 查看列出所有信息。
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.1  19360  1616 ?        Ss   08:04   0:02 /sbin/init
root          2  0.0  0.0      0     0 ?        S    08:04   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    08:04   0:00 [migration/]
root          4  0.0  0.0      0     0 ?        S    08:04   0:00 [ksoftirqd/]
root          5  0.0  0.0      0     0 ?        S    08:04   0:00 [stopper/0]
root          6  0.0  0.0      0     0 ?        S    08:04   0:00 [watchdog/0]
root          7  0.0  0.0      0     0 ?        S    08:04   0:00 [migration/]
root          8  0.0  0.0      0     0 ?        S    08:04   0:00 [stopper/1]
USER  以用户为中心
PID为进程号码  
%CPU 所用的比率
%MEM 累计内存占用比率
以上所显示的的信息依次为:
VSZ:虚拟内存集;
RSS:Resident Size,常驻内存集;
STAT:状态分一下集中情况:
R:running  运行态
S:interruptable sleeping  可中断睡眠
D:uninterruptable sleeping  不可中断睡眠
T:Stopped 停止态
Z:zombie 僵死态
+:前台进程
l:多线程进程
N:低优先级进程f
<:高优先级进程  
s:session leader 回话主导者
ps -e  命令的意思是显示所有进程:

[iyunv@server cx]# ps -e
   PID TTY          TIME CMD
     1 ?        00:00:02 init
     2 ?        00:00:00 kthreadd
     3 ?        00:00:00 migration/0
     4 ?        00:00:00 ksoftirqd/0
     5 ?        00:00:00 stopper/0
     6 ?        00:00:00 watchdog/0
     7 ?        00:00:00 migration/1
     8 ?        00:00:00 stopper/1
     9 ?        00:00:00 ksoftirqd/1
    10 ?        00:00:00 watchdog/1
    11 ?        00:00:48 events/0
    12 ?        00:00:06 events/1
    13 ?        00:00:00 events/0
    14 ?        00:00:00 events/1
    15 ?        00:00:00 events_long/
ps -ef 显示更为详细的所有进程信息:

[iyunv@server cx]# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 08:04 ?        00:00:02 /sbin/init
root          2      0  0 08:04 ?        00:00:00 [kthreadd]
root          3      2  0 08:04 ?        00:00:00 [migration/0]
root          4      2  0 08:04 ?        00:00:00 [ksoftirqd/0]
root          5      2  0 08:04 ?        00:00:00 [stopper/0]
root          6      2  0 08:04 ?        00:00:00 [watchdog/0]
root          7      2  0 08:04 ?        00:00:00 [migration/1]
root          8      2  0 08:04 ?        00:00:00 [stopper/1]
root          9      2  0 08:04 ?        00:00:00 [ksoftirqd/1]
root         10      2  0 08:04 ?        00:00:00 [watchdog/1]
root         11      2  0 08:04 ?        00:00:48 [events/0]
root         12      2  0 08:04 ?        00:00:06 [events/1]
root         13      2  0 08:04 ?        00:00:00 [events/0]
root         14      2  0 08:04 ?        00:00:00 [events/1]
root         15      2  0 08:04 ?        00:00:00 [events_long/0]
root         16      2  0 08:04 ?        00:00:00 [events_long/1]
root         17      2  0 08:04 ?        00:00:00 [events_power_ef]
root         18      2  0 08:04 ?        00:00:00 [events_power_ef]
root         19      2  0 08:04 ?        00:00:00 [cgroup]
root         20      2  0 08:04 ?        00:00:00 [khelper]
ps -eF 命令的意思是显示更详细进程的信息:

[iyunv@server cx]# ps -eF
UID         PID   PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root          1      0  0  4840  1616   1 08:04 ?        00:00:02 /sbin/init
root          2      0  0     0     0   1 08:04 ?        00:00:00 [kthreadd]
root          3      2  0     0     0   0 08:04 ?        00:00:00 [migration/]
root          4      2  0     0     0   0 08:04 ?        00:00:00 [ksoftirqd/]
root          5      2  0     0     0   0 08:04 ?        00:00:00 [stopper/0]
root          6      2  0     0     0   0 08:04 ?        00:00:00 [watchdog/0]
root          7      2  0     0     0   1 08:04 ?        00:00:00 [migration/]
root          8      2  0     0     0   1 08:04 ?        00:00:00 [stopper/1]
root          9      2  0     0     0   1 08:04 ?        00:00:00 [ksoftirqd/]
root         10      2  0     0     0   1 08:04 ?        00:00:00 [watchdog/1]
root         11      2  0     0     0   0 08:04 ?        00:00:48 [events/0]
root         12      2  0     0     0   1 08:04 ?        00:00:06 [events/1]
root         13      2  0     0     0   0 08:04 ?        00:00:00 [events/0]
root         14      2  0     0     0   1 08:04 ?        00:00:00 [events/1]
root         15      2  0     0     0   0 08:04 ?        00:00:00 [events_lon]
root         16      2  0     0     0   1 08:04 ?        00:00:00 [events_lon]
root         17      2  0     0     0   0 08:04 ?        00:00:00 [events_pow]
root         18      2  0     0     0   1 08:04 ?        00:00:00 [events_pow]
ps -eFH命令的意思是以层级结构显示进程的相关信息。
ps -o +字段+字段,,;自定义要显示的字段列表,以逗号分隔。


常用的字段有:field:pid, ni, pri, psr, pcpu, stat, comm, tty, ppid, rtprioni:nice值;

priority:priority, 优先级;rtprio:real time priority,实时优先级
ps -eo

ps -axo + pid,canmand 显示进程号和command 两个信息

[iyunv@server cx]# ps -axo pid,command
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
   PID COMMAND
     1 /sbin/init
     2 [kthreadd]
     3 [migration/0]
     4 [ksoftirqd/0]
     5 [stopper/0]
     6 [watchdog/0]
     7 [migration/1]
     8 [stopper/1]
     9 [ksoftirqd/1]
    10 [watchdog/1]
    11 [events/0]
二、top命令常用参数选项

top +        -d #:指定刷新时间间隔,默认为3秒;如下是命令使用格式:
[iyunv@server cx]# top -d 5
top +        -b:以批次方式显示;如下是命令使用格式:
[iyunv@server cx]# top -b
top +        -n #:显示多少批次;如下是命令使用格式:
[iyunv@server cx]# top -n 2
三、dstat命令常用参数选项

dstat命令:
- versatile tool for generating system resource statistics
dstat [-afv] [options..] [delay [count]]
常用选项:
dstat -c, --cpu:显示cpu相关信息;例如:
[iyunv@server cx]# dstat -c
----total-cpu-usage----
usr sys idl wai hiq siq
  0   0 100   0   0   0
  0   0 100   0   0   0
  0   0 100   0   0   0
  0   0 100   0   0   0
  0   0 100   0   0   0
  0   1 100   0   0   0
  0   0 100   0   0   0
dstat -C #,#,...,total 显示第几号CPU的相关信息:例如:
[iyunv@server cx]# dstat -C 1
-------cpu1-usage------ -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw
  0   0 100   0   0   0|8241B 2672B|   0     0 |   0     0 |  28    29
  0   0 100   0   0   0|   0     0 | 180B  826B|   0     0 |  22    21
  0   0 100   0   0   0|   0     0 | 180B  346B|   0     0 |  40    37
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  95    69
  0   0 100   0   0   0|   0     0 | 180B  346B|   0     0 |  35    32
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  21    15
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  33    36
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  16    13 ^C
dstat -d, --disk:显示磁盘的相关信息
[iyunv@server cx]# dstat -d
-dsk/total-
read  writ
8227B 2672B
   0     0
   0     0 ^C
[iyunv@server cx]# dstat --disk
-dsk/total-
read  writ
8226B 2671B
   0     0
   0     0
   0     0 ^C
dstat -D sda,sdb,...,tobal   (命令的使用方法一样)
dstat -g:显示page相关的速率数据;(命令的使用方法一样)
dstat -m:Memory的相关统计数据 :(命令的使用方法一样)
dstat -n:Interface的相关统计数据; (命令的使用方法一样)
dstat -p:显示process的相关统计数据; (命令的使用方法一样)
dstat -r:显示io请求的相关的统计数据;(命令的使用方法一样)
dstat -s:显示swapped的相关统计数据;(命令的使用方法一样)
[iyunv@server cx]# dstat -s
----swap---
used  free
   0  2000M
   0  2000M
   0  2000M
   0  2000M
   0  2000M
--tcp
[iyunv@server cx]# dstat --tcp
----tcp-sockets----
lis act syn tim clo
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0
11   1   0   0   0

dstat --udp 显示upd相关的信息
dstat --raw  显示raw相关的信息
dstat --socket 显示socket相关的信息
dstat --ipc  显示ipc相关的信息
[iyunv@server cx]# dstat --ipc
--sysv-ipc-
msg sem shm
  0   2   4
  0   2   4
  0   2   4
  0   2   4
  0   2   4
  0   2   4
  0   2   4
dstat --top-cpu:显示最占用CPU的进程,例如:

[iyunv@server cx]# dstat --top-cpu
-most-expensive-
  cpu process   
events/0     0.1

dstat --top-io:最占用io的进程;

[iyunv@server cx]# dstat --top-io
----most-expensive----
     i/o process      
init       1835B 2785B
irqbalance 7620B    0
ksmtuned    126k   10B
sshd: root@  78B  116B
sshd: root@  78B  116B
sshd: root@  78B  116B

dstat --top-mem:最占用内存的进程;

[iyunv@server cx]# dstat --top-mem
--most-expensive-
  memory process
Xorg        22.0M
Xorg        22.0M
Xorg        22.0M
Xorg        22.0M

dstat --top-lantency:延迟最大的进程;

四、htop命令使用详解

htop命令常用选项参数如下:
选项:
-d #:指定延迟时间间隔;命令的语法如下所示:
htop -d  3  间隔时间为3S
-u UserName:仅显示指定用户的进程;命令的语法如下所示:

htop -u wen 显示用户名为wen的进程信息
-s COLUME:以指定字段进行排序;
子命令:
l:显示选定的进程打开的文件列表;
s:跟踪选定的进程的系统调用;
t:以层级关系显示各进程状态;
a:将选定的进程绑定至某指定的CPU核心;

好了,今天就写到这里吧,这是经常用的一些linux常用管理工具,跟着马哥继续努力吧。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-195289-1-1.html 上篇帖子: edquota 给账号分配磁盘配额 下篇帖子: dpdk网卡绑定和解绑
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表