Linux进程管理——查看内存的工具

一查看内存的工具vmstat

vmstat命令:虚拟内存信息
vmstat [options] [delay [count]]
vmstat 2 5

  1. [root@centos72 ~]# vmstat
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 1 0 0 610224 2076 279392 0 0 32 9 316 55 8 19 73 1 0
  5. [root@centos72 ~]# rpm -q vmstat
  6. package vmstat is not installed
  7. [root@centos72 ~]# type vmstat
  8. vmstat is hashed (/usr/bin/vmstat)
  1. [root@centos72 ~]# free
  2. total used free shared buff/cache available
  3. Mem: 997980 106532 609936 7832 281512 705116
  4. Swap: 2097148 0

详细选项:
procs:
r:可运行(正运行或等待运行)进程的个数,和核心数有关
b:处于不可中断睡眠态的进程个数(被阻塞的队列的长度)
memory:
swpd: 交换内存的使用总量
free:空闲物理内存总量
buffer:用于buffer的内存总量
cache:用于cache的内存总量

注意buffer和cache的区别

swap:
si:从磁盘交换进内存的数据速率(kb/s)
so:从内存交换至磁盘的数据速率(kb/s)

查看帮助文档

  1. Swap
  2. si: Amount of memory swapped in from disk (/s).
  3. so: Amount of memory swapped to disk (/s).

io:
bi:从块设备读入数据到系统的速率(kb/s),也就是出磁盘进内存
bo: 保存数据至块设备的速率,也就是进磁盘出内存

  1. IO
  2. bi: Blocks received from a block device (blocks/s).
  3. bo: Blocks sent to a block device (blocks/s).

设置1秒执行一次

  1. [root@centos72 ~]# vmstat 1
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 1 0 0 758312 2076 134872 0 0 56 5 68 82 0 0 98 2 0
  5. 0 0 0 758288 2076 134872 0 0 0 0 55 41 0 0 100 0 0
  6. 0 0 0 758288 2076 134872 0 0 0 0 52 46 0 0 100 0 0
  7. 0 0 0 758288 2076 134872 0 0 0 0 52 45 0 0 100 0 0
  8. 0 0 0 758288 2076 134872 0 0 0 0 56 48 0 0 100 0 0
  9. 0 0 0 758288 2076 134872 0 0 0 0 45 33 0 0 100 0 0
  10. 0 0 0 758288 2076 134872 0 0 0 0 50 42 0 0 100 0

top命令也有一样的选项

  1. top - 00:50:39 up 49 min, 2 users, load average: 0.00, 0.01, 0.05
  2. Tasks: 104 total, 1 running, 103 sleeping, 0 stopped, 0 zombie
  3. %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  4. KiB Mem : 997980 total, 757148 free, 103336 used, 137496 buff/cache
  5. KiB Swap: 2097148 total, 2097148 free, 0 used. 733212 avail Mem
  6.  
  7. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  8. 1 root 20 0 193316 6412 4080 S 0.0 0.6 0:01.47 systemd
  9. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
  10. 3 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/0
  11. 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
  12. 6 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u256:0
  13. 7 root rt 0 0 0 0 S 0.0 0.0 0:00.04 migration/0
  14. 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
  15. 9 root 20 0 0 0 0 S 0.0 0.0 0:00.33 rcu_sched
  16. 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
  17. 11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
  18. 12 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/1
  19. 13 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
  20. 14 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/1
  21. 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
  22. 18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs

system:
in: interrupts 中断速率,包括时钟
cs: context switch 进程切换速率,切换高不好

这和学习一样,要集中精力才会效率高

cpu:
us:Time spent running non-kernel code
sy: Time spent running kernel code
id: Time spent idle. Linux 2.5.41前,包括IO-wait time.
wa: Time spent waiting for IO. 2.5.41前,包括in idle.
st: Time stolen from a virtual machine. 2.6.11前, unknown.

开启一个进程,可以看到刚开始是出内存的多

因为内存空间满了就要里面的内容导到交换分区里面

  1. [root@centos72 ~]# vmstat 1
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 3 0 0 138112 2076 135496 0 0 15 1 40 38 0 0 99 0 0
  5. 0 7 135944 48976 0 67688 128 227088 9540 227089 5203 777 0 10 14 76 0
  6. 0 8 280072 48764 0 59576 224 63932 6664 63948 1314 244 0 3 0 97 0
  7. 0 7 317960 48800 0 63960 8 26792 256 26792 646 241 0 1 0 99 0
  8. 0 8 355080 64672 0 65012 276 37012 1348 37012 1428 218 0 3 7 91 0
  9. 0 8 402696 64132 0 65596 96 47628 260 47628 210 60 0 2 0 99 0
  10. 0 10 429832 49148 0 65448 120 27140 304 27140 248 101 0 1 0 99 0
  11. 0 10 489224 48824 0 58192 128 91312 8772 91312 2527 384 0 5 0 95 0
  12. 1 9 567296 72648 0 61268 96 46084 220 46084 355 164 0 1 0 99 0
  13. 4 9 582152 48704 0 60316 280 14696 676 14696 12712 295 0 33 0 67 0
  14. 4 9 590344 48880 0 61336 32 8456 1096 8456 102 50 0 9 0 91 0
  15. 8 9 618240 50096 0 60216 52 28704 316 28704 902 134 0 11 0 89 0
  16. 14 10 651520 48860 0 61432 32 32524 32 32524 1077 193 0 14 0 86 0
  17. 2 12 686080 48812 0 61740 32 34676 144 34676 702 140 0 9 62 29 0
  18. 9 8 702720 49164 0 60936 176 16480 436 16480 4339 89 0 20 0 80 0
  19. 10 6 747776 48884 0 61076 256 45080 592 45080 4401 104 0 62 0 38 0
  20. 9 7 764048 49992 0 60044 204 16836 584 16836 3782 69 0 25 0 75 0
  21. 12 7 838912 56412 0 61520 128 74664 296 74664 385 91 0 14 0 86 0
  22. 2 10 866560 52044 0 63116 288 27408 1476 27408 4312 334 0 16 0 84

让bi值变大,那么就要从磁盘读取数据,也就是出磁盘进内存

比如从第1块硬盘读数据到垃圾箱里面

  1. [root@centos72 ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/sda2 50G 1.3G 49G 3% /
  4. devtmpfs 477M 0 477M 0% /dev
  5. tmpfs 488M 0 488M 0% /dev/shm
  6. tmpfs 488M 7.6M 480M 2% /run
  7. tmpfs 488M 0 488M 0% /sys/fs/cgroup
  8. /dev/sda3 20G 33M 20G 1% /app
  9. /dev/sda1 1014M 124M 891M 13% /boot
  10. tmpfs 98M 0 98M 0% /run/user/0
  11. [root@centos72 ~]# dd if=/dev/sda of=/dev/null
  1. [root@centos72 ~]# vmstat 1
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 1 0 49864 815124 0 108072 0 13 3 14 25 21 0 0 100 0 0
  5. 0 0 49864 815124 0 108132 0 0 0 0 64 48 0 0 100 0 0
  6. 0 0 49864 815124 0 108132 0 0 0 0 55 43 0 0 100 0 0
  7. 0 0 49864 815124 0 108132 0 0 0 0 54 46 0 0 100 0 0
  8. 1 0 49864 770112 44880 108124 0 0 44880 0 485 178 0 10 66 24 0
  9. 0 1 49864 688412 126800 108104 0 0 81920 0 878 255 1 23 50 27 0
  10. 1 0 49864 528276 286544 108496 0 0 159744 0 1229 63 1 43 50 7 0
  11. 1 0 49864 376412 438096 108768 0 0 151552 0 1295 55 1 46 51 2 0
  12. 1 0 49864 236780 577360 109164 0 0 139264 0 1226 65 1 37 49 13 0
  13. 1 0 49864 72624 741200 109524 0 0 163840 0 1438 83 1 45 50 6 0
  14. 0 1 49864 72048 774588 76588 0 0 282640 395 1588 206 6 37 48 9 0
  15. 1 0 49864 62660 783960 76780 0 0 69632 0 424 129 2 7 50 41 0
  16. 0 1 49864 77532 768896 76824 0 0 57344 0 381 237 1 5 50 44 0
  17. 0 1 49864 73128 773868 76776 0 0 53248 0 362 195 2 5 50 44 0
  18. 0 1 49864 68116 778744 76876 0 0 53248 0 373 182 1 6 50 43 0
  19. 0 1 49864 81316 765416 76972 0 0 28672 0 225 128 1 3 50 47 0
  20. 0 1 49864 77328 770300 76932 0 0 53248 0 334 164 1 6 50 43 0
  21. 0 1 49864 80312 767308 77004 0 0 69632 2 549 377 2 7 51 41 0
  22. 0 1 49864 65336 782208 77044 0 0 32768 0 205 79 1 3 50 46 0
  23. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  24. r b swpd free buff cache si so bi bo in cs us sy id wa st
  25. 2 0 49864 61616 789040 75848 0 0 139264 0 731 144 3 14 50 34 0
  26. 1 0 49864 73440 778604 76144 0 0 368640 0 1803 192 9 36 48 7 0
  27. 1 0 49864 68620 781404 76724 0 0 355840 0 1620 127 9 33 48 9 0
  28. 1 0 49864 64616 787500 76324 0 0 356864 0 1643 130 9 34 48 9 0
  29. 1 0 49864 66344 785224 76788 0 0 282636 8 1469 110 10 35 50 5 0
  30. 2 0 49864 77792 773020 77444 0 0 315392 0 1497 87 10 34 49 7 0
  31. 1 0 49864 80512 769484 78296 0 0 311380 0 1573 133 9 37 51 3 0
  32. 1 0 49864 66492 780540 78940 0 0 359424 0 1628 99 10 34 48 7 0
  33. 1 0 49864 67068 784196 76760 0 0 353280 0 1608 126 9 34 49 9 0
  34. 1 0 49864 81676 768808 77612 0 0 360456 20 1633 112 9 36 48 8 0
  35. 0 1 49864 64044 785580 78316 0 0 344064 0 1554 112 8 33 49 10 0
  36. 0 1 49864 69752 779612 78728 0 0 393216 0 1885 197 10 40 48 4 0
  37. 1 0 49864 62060 787120 78864 0 0 397312 0 1909 212 10 37 48 5 0
  38. 1 0 49864 64728 784528 78816 0 0 360448 0 1837 210 9 36 48 7 0
  39. 1 0 49864 66900 782292 78908 0 0 372736 0 1839 215 9 37 48 7 0
  40. 1 0 49864 69976 779204 79032 0 0 323584 0 1541 175 8 30 49 13 0
  41. 1 0 49864 71012 778260 78928 0 0 376832 0 1838 239 9 36 48 7 0
  42. 1 0 49864 68520 780676 78680 0 0 425984 0 2076 245 10 41 48 1 0
  43. 1 0 49864 75060 774076 78792 0 0 331776 0 1723 225 10 34 48 9

增加bo值

  1. [root@centos72 ~]# dd if=/dev/sda of=/f1
  1. [root@centos72 ~]# vmstat 1
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 1 0 49864 73816 771396 83032 0 13 668 14 29 21 0 0 100 0 0
  5. 0 0 49864 73692 771396 83008 0 0 0 0 65 51 0 0 100 0 0
  6. 1 0 49864 80052 745316 102564 0 0 24436 0 311 134 0 7 80 13 0
  7. 2 1 49864 74568 690624 162564 0 0 65536 76112 674 298 2 18 46 35 0
  8. 7 1 49864 71944 680280 175740 0 0 8192 0 284 49 3 18 59 21 0
  9. 8 0 49864 76776 611136 238508 0 0 59904 2048 706 143 2 24 52 21 0
  10. 4 0 49864 64664 594468 267612 0 0 28672 30723 367 95 6 70 24 0 0
  11. 3 1 49864 74676 576804 276384 0 0 9728 72016 168 44 0 9 63 28 0
  12. 3 1 49864 76316 566944 284776 0 0 8192 0 136 37 3 18 26 54 0
  13. 11 1 49864 76316 566944 284776 0 0 0 0 90 13 0 100 0 0 0
  14. 5 0 49864 75400 497952 354624 0 0 65536 10752 908 197 3 29 45 23 0
  15. 7 1 49864 64288 487396 376180 0 0 32768 98996 269 119 5 75 20 0 0
  16. 5 1 49864 77980 452188 398160 0 0 12288 0 443 65 2 16 60 23 0
  17. 1 0 49864 62728 388992 476024 0 0 77824 28672 1011 159 4 52 39 4 0
  18. 3 1 49864 72916 372744 482036 0 0 8192 0 78 34 6 19 56 19 0
  19. 5 0 49864 64288 362128 498940 0 0 13824 16896 251 59 5 59 18 18 0
  20. 6 0 49864 78640 332404 516352 0 0 18944 74536 221 49 2 21 42 35 0

-s: 显示内存的统计数据

  1. [root@centos72 ~]# vmstat -s
  2. 997980 K total memory
  3. 69504 K used memory
  4. 387508 K active memory
  5. 403720 K inactive memory
  6. 81120 K free memory
  7. 180292 K buffer memory
  8. 667064 K swap cache
  9. 2097148 K total swap
  10. 49864 K used swap
  11. 2047284 K free swap
  12. 3626 non-nice user cpu ticks
  13. 2 nice user cpu ticks
  14. 15279 system cpu ticks
  15. 7273227 idle cpu ticks
  16. 17014 IO-wait cpu ticks
  17. 0 IRQ cpu ticks
  18. 496 softirq cpu ticks
  19. 0 stolen cpu ticks
  20. 50988602 pages paged in
  21. 3212894 pages paged out
  22. 5460 pages swapped in
  23. 243937 pages swapped out
  24. 2116104 interrupts
  25. 1576029 CPU context switches
  26. 1558281696 boot time
  27. 1757 forks

定义显示次数

  1. [root@centos72 ~]# vmstat 1 3
  2. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  3. r b swpd free buff cache si so bi bo in cs us sy id wa st
  4. 2 0 48584 64156 403812 459696 0 13 1653 59 35 23 0 0 99 0 0
  5. 2 0 48584 64308 404496 458928 0 0 376832 0 2437 243 10 37 48 6 0
  6. 0 1 48584 63416 406468 457848 0 0 401408 0 2549 260 8 41 47 4 0
  7. [root@centos72 ~]# vmstat 1 6
  8. procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  9. r b swpd free buff cache si so bi bo in cs us sy id wa st
  10. 1 1 48584 69340 398596 459876 0 13 1682 59 35 23 0 0 99 0 0
  11. 0 1 48584 69576 398320 459772 0 0 61440 0 579 257 2 6 50 42 0
  12. 1 0 48584 64820 403060 459828 0 0 45056 0 427 166 1 5 50 45 0
  13. 0 1 48584 61972 406012 459792 0 0 77824 0 649 244 2 8 50 40 0
  14. 0 1 48584 63092 404844 459748 0 0 73728 0 618 278 2 7 50 41 0
  15. 0 1 48584 73948 394792 458848 0 0 69632 0 588 236 1 7 50 42

二iostat:统计CPU和设备IO信息

  1. [root@centos72 ~]# yum repolist
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. base | 3.6 kB 00:00:00
  5. repo id repo name status
  6. base base 3,971
  7. repolist: 3,971
  8. [root@centos72 ~]# yum whatprovides iostat
  9. Loaded plugins: fastestmirror
  10. Loading mirror speeds from cached hostfile
  11. sysstat-10.1.5-13.el7.x86_64 : Collection of performance monitoring tools for Linux
  12. Repo : base
  13. Matched from:
  14. Filename : /usr/bin/iostat
  15.  
  16. [root@centos72 ~]# yum install sysstat -y
  17. Loaded plugins: fastestmirror
  18. Loading mirror speeds from cached hostfile
  19. Resolving Dependencies
  20. --> Running transaction check
  21. ---> Package sysstat.x86_64 0:10.1.5-13.el7 will be installed
  22. --> Processing Dependency: libsensors.so.4()(64bit) for package: sysstat-10.1.5-13.el7.x86_64
  23. --> Running transaction check
  24. ---> Package lm_sensors-libs.x86_64 0:3.4.0-4.20160601gitf9185e5.el7 will be installed
  25. --> Finished Dependency Resolution
  26.  
  27. Dependencies Resolved
  28.  
  29. ========================================================================================================
  30. Package Arch Version Repository Size
  31. ========================================================================================================
  32. Installing:
  33. sysstat x86_64 10.1.5-13.el7 base 310 k
  34. Installing for dependencies:
  35. lm_sensors-libs x86_64 3.4.0-4.20160601gitf9185e5.el7 base 41 k
  36.  
  37. Transaction Summary
  38. ========================================================================================================
  39. Install 1 Package (+1 Dependent package)
  40.  
  41. Total download size: 352 k
  42. Installed size: 1.2 M
  43. Downloading packages:
  44. --------------------------------------------------------------------------------------------------------
  45. Total 705 kB/s | 352 kB 00:00:00
  46. Running transaction check
  47. Running transaction test
  48. Transaction test succeeded
  49. Running transaction
  50. Installing : lm_sensors-libs-3.4.0-4.20160601gitf9185e5.el7.x86_64 1/2
  51. Installing : sysstat-10.1.5-13.el7.x86_64 2/2
  52. Verifying : sysstat-10.1.5-13.el7.x86_64 1/2
  53. Verifying : lm_sensors-libs-3.4.0-4.20160601gitf9185e5.el7.x86_64 2/2
  54.  
  55. Installed:
  56. sysstat.x86_64 0:10.1.5-13.el7
  57.  
  58. Dependency Installed:
  59. lm_sensors-libs.x86_64 0:3.4.0-4.20160601gitf9185e5.el7
  60.  
  61. Complete!

下面都是完整的单词,之前是简写

avg-cpu: %user %nice %system %iowait %steal %idle

tps  每秒钟处理的事务

kB_read/s  每秒钟从磁盘读取的字节数?

kB_wrtn/s 每秒钟从磁盘写入的字节数?

kB_read

kB_wrtn

  1. [root@centos72 ~]# iostat
  2. Linux 3.10.0-862.el7.x86_64 (centos72.huawei.com) 05/20/2019 _x86_64_ (2 CPU)
  3.  
  4. avg-cpu: %user %nice %system %iowait %steal %idle
  5. 0.05 0.00 0.22 0.25 0.00 99.49
  6.  
  7. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  8. scd0 0.01 0.08 0.00 2978 0
  9. sda 3.11 1378.58 86.82 51100818
  1. [root@centos65 ~]# iostat
  2. Linux 2.6.32-642.el6.x86_64 (centos65.jd.com) 05/20/2019 _x86_64_ (2 CPU)
  3.  
  4. avg-cpu: %user %nice %system %iowait %steal %idle
  5. 0.00 0.00 0.04 0.08 0.00 99.87
  6.  
  7. Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
  8. sda 0.29 6.47 1.34 238874 49352
  9. scd0 0.00 0.01 0.00 528

从磁盘里读数据,并且设置时间间隔显示一次

  1. [root@centos72 ~]# dd if=/dev/sda of=/dev/null
  1. [root@centos72 ~]# iostat 1
  2. Linux 3.10.0-862.el7.x86_64 (centos72.huawei.com) 05/20/2019 _x86_64_ (2 CPU)
  3.  
  4. avg-cpu: %user %nice %system %iowait %steal %idle
  5. 0.05 0.00 0.23 0.26 0.00 99.46
  6.  
  7. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  8. scd0 0.01 0.08 0.00 2978 0
  9. sda 3.25 1412.10 117.79 53159598 4434194
  10.  
  11. avg-cpu: %user %nice %system %iowait %steal %idle
  12. 5.56 0.00 22.22 24.24 0.00 47.98
  13.  
  14. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  15. scd0 0.00 0.00 0.00 0 0
  16. sda 470.00 240136.00 0.00 240136 0
  17.  
  18. avg-cpu: %user %nice %system %iowait %steal %idle
  19. 1.01 0.00 4.55 44.44 0.00 50.00
  20.  
  21. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  22. scd0 0.00 0.00 0.00 0 0
  23. sda 93.00 47616.00 0.00 47616 0
  24.  
  25. avg-cpu: %user %nice %system %iowait %steal %idle
  26. 1.03 0.00 4.62 43.59 0.00 50.77
  27.  
  28. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  29. scd0 0.00 0.00 0.00 0 0
  30. sda 128.00 65536.00 0.00 65536 0
  31.  
  32. avg-cpu: %user %nice %system %iowait %steal %idle
  33. 1.53 0.00 5.10 43.37 0.00 50.00
  34.  
  35. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  36. scd0 0.00 0.00 0.00 0 0
  37. sda 124.00 63488.00 0.00 63488 0
  38.  
  39. avg-cpu: %user %nice %system %iowait %steal %idle
  40. 1.00 0.00 4.00 45.00 0.00 50.00
  41.  
  42. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  43. scd0 0.00 0.00 0.00 0 0
  44. sda 87.00 44544.00 0.00 44544 0
  45.  
  46. avg-cpu: %user %nice %system %iowait %steal %idle
  47. 1.02 0.00 4.57 44.16 0.00 50.25
  48.  
  49. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  50. scd0 0.00 0.00 0.00 0 0
  51. sda 98.00 50176.00 0.00 50176 0
  52.  
  53. avg-cpu: %user %nice %system %iowait %steal %idle
  54. 1.03 0.00 6.15 42.56 0.00 50.26
  55.  
  56. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  57. scd0 0.00 0.00 0.00 0 0
  58. sda 132.00 67584.00 0.00 67584

此命令的作用就是可以查看磁盘访问的压力大小

定义显示次数

  1. [root@centos72 ~]# iostat 1 4
  2. Linux 3.10.0-862.el7.x86_64 (centos72.huawei.com) 05/20/2019 _x86_64_ (2 CPU)
  3.  
  4. avg-cpu: %user %nice %system %iowait %steal %idle
  5. 0.08 0.00 0.35 0.38 0.00 99.19
  6.  
  7. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  8. scd0 0.01 0.08 0.00 2978 0
  9. sda 5.76 2694.01 117.16 101963082 4434320
  10.  
  11. avg-cpu: %user %nice %system %iowait %steal %idle
  12. 10.05 0.00 40.70 3.52 0.00 45.73
  13.  
  14. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  15. scd0 0.00 0.00 0.00 0 0
  16. sda 835.00 426092.00 0.00 426092 0
  17.  
  18. avg-cpu: %user %nice %system %iowait %steal %idle
  19. 8.50 0.00 35.00 8.50 0.00 48.00
  20.  
  21. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  22. scd0 0.00 0.00 0.00 0 0
  23. sda 697.03 356879.21 0.00 360448 0
  24.  
  25. avg-cpu: %user %nice %system %iowait %steal %idle
  26. 9.60 0.00 35.86 7.07 0.00 47.47
  27.  
  28. Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
  29. scd0 0.00 0.00 0.00 0 0
  30. sda 736.00 376832.00 0.00 376832

三pmap命令

pmap命令:进程对应的内存映射,也就是进程使用的内存空间
pmap [options] pid [...]
-x: 显示详细格式的信息

  1. [root@centos72 ~]# dd if=/dev/sda of=/dev/null

调用了很多库,也是要占空间的

很多模块都可能使用到相同的库,相当于公共设施

  1. [root@centos72 ~]# pstree -p
  2. systemd(1)─┬─NetworkManager(557)─┬─{NetworkManager}(594)
  3. └─{NetworkManager}(596)
  4. ├─VGAuthService(546)
  5. ├─agetty(573)
  6. ├─auditd(517)───{auditd}(518)
  7. ├─crond(567)
  8. ├─dbus-daemon(550)───{dbus-daemon}(556)
  9. ├─irqbalance(549)
  10. ├─master(873)─┬─pickup(1594)
  11. └─qmgr(875)
  12. ├─polkitd(540)─┬─{polkitd}(576)
  13. ├─{polkitd}(577)
  14. ├─{polkitd}(582)
  15. ├─{polkitd}(586)
  16. └─{polkitd}(587)
  17. ├─rsyslogd(791)─┬─{rsyslogd}(793)
  18. └─{rsyslogd}(794)
  19. ├─sshd(788)─┬─sshd(1076)───bash(1081)───dd(1729)
  20. └─sshd(1599)───bash(1603)───pstree(1743)
  21. ├─systemd-journal(356)
  22. ├─systemd-logind(543)
  23. ├─systemd-udevd(390)
  24. ├─tuned(789)─┬─{tuned}(1030)
  25. ├─{tuned}(1031)
  26. ├─{tuned}(1032)
  27. └─{tuned}(1046)
  28. └─vmtoolsd(547)───{vmtoolsd}(579)
  29. [root@centos72 ~]# pmap 1729
  30. 1729: dd if=/dev/sda of=/dev/null
  31. 0000000000400000 68K r-x-- dd
  32. 0000000000610000 4K r---- dd
  33. 0000000000611000 4K rw--- dd
  34. 0000000000de9000 132K rw--- [ anon ]
  35. 00007fd21a123000 103588K r---- locale-archive
  36. 00007fd22064c000 1804K r-x-- libc-2.17.so
  37. 00007fd22080f000 2044K ----- libc-2.17.so
  38. 00007fd220a0e000 16K r---- libc-2.17.so
  39. 00007fd220a12000 8K rw--- libc-2.17.so
  40. 00007fd220a14000 20K rw--- [ anon ]
  41. 00007fd220a19000 136K r-x-- ld-2.17.so
  42. 00007fd220c31000 12K rw--- [ anon ]
  43. 00007fd220c39000 4K rw--- [ anon ]
  44. 00007fd220c3a000 4K r---- ld-2.17.so
  45. 00007fd220c3b000 4K rw--- ld-2.17.so
  46. 00007fd220c3c000 4K rw--- [ anon ]
  47. 00007ffeeedc9000 132K rw--- [ stack ]
  48. 00007ffeeedf7000 8K r-x-- [ anon ]
  49. ffffffffff600000 4K r-x-- [ anon ]
  50. total 107996K

另外一种实现:
cat /proc/PID/maps

实际上是看此文件的内容,但是这样看易读性差

做开发可能会涉及到内存泄漏问题

内存泄漏就是进程占用了内存之后一直不释放内存,占满了还会继续占用,直到所有的内存占满导致系统奔溃

所以运维和开发不分家,平时遇到了什么问题要和开发沟通

  1. [root@centos72 ~]# ls /proc/1729/maps -l
  2. -r--r--r--. 1 root root 0 May 20 10:35 /proc/1729/maps
  3. [root@centos72 ~]# cat /proc/1729/maps
  4. 00400000-00411000 r-xp 00000000 08:02 21443 /usr/bin/dd
  5. 00610000-00611000 r--p 00010000 08:02 21443 /usr/bin/dd
  6. 00611000-00612000 rw-p 00011000 08:02 21443 /usr/bin/dd
  7. 00de9000-00e0a000 rw-p 00000000 00:00 0 [heap]
  8. 7fd21a123000-7fd22064c000 r--p 00000000 08:02 228723 /usr/lib/locale/locale-archive
  9. 7fd22064c000-7fd22080f000 r-xp 00000000 08:02 33600202 /usr/lib64/libc-2.17.so
  10. 7fd22080f000-7fd220a0e000 ---p 001c3000 08:02 33600202 /usr/lib64/libc-2.17.so
  11. 7fd220a0e000-7fd220a12000 r--p 001c2000 08:02 33600202 /usr/lib64/libc-2.17.so
  12. 7fd220a12000-7fd220a14000 rw-p 001c6000 08:02 33600202 /usr/lib64/libc-2.17.so
  13. 7fd220a14000-7fd220a19000 rw-p 00000000 00:00 0
  14. 7fd220a19000-7fd220a3b000 r-xp 00000000 08:02 33600195 /usr/lib64/ld-2.17.so
  15. 7fd220c31000-7fd220c34000 rw-p 00000000 00:00 0
  16. 7fd220c39000-7fd220c3a000 rw-p 00000000 00:00 0
  17. 7fd220c3a000-7fd220c3b000 r--p 00021000 08:02 33600195 /usr/lib64/ld-2.17.so
  18. 7fd220c3b000-7fd220c3c000 rw-p 00022000 08:02 33600195 /usr/lib64/ld-2.17.so
  19. 7fd220c3c000-7fd220c3d000 rw-p 00000000 00:00 0
  20. 7ffeeedc9000-7ffeeedea000 rw-p 00000000 00:00 0 [stack]
  21. 7ffeeedf7000-7ffeeedf9000 r-xp 00000000 00:00 0 [vdso]
  22. ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]

文件描述符表示进程打开了文件数量

如果数量不断增加说明有问题,因为内存空间是有限的,进程占用的资源是有限的

如果出现此问题那么就要找开发

  1. [root@centos72 ~]# ls /proc/1800/fd
  2. 0 1 2
  3. [root@centos72 ~]#
  1. [root@centos72 ~]# ls /proc/1800/fd
  2. 0 1 2
  3. [root@centos72 ~]# ls /proc/1800/fd
  4. 0 1 2
  5. [root@centos72 ~]# ls /proc/1800/fd
  6. 0 1 2
  7. [root@centos72 ~]# ls /proc/1800/fd
  8. 0 1 2
  9. [root@centos72 ~]# ls /proc/1800/fd
  10. 0 1 2
  11. [root@centos72 ~]# ls /proc/1800/fd -al
  12. total 0
  13. dr-x------. 2 root root 0 May 20 10:46 .
  14. dr-xr-xr-x. 9 root root 0 May 20 10:45 ..
  15. lr-x------. 1 root root 64 May 20 10:46 0 -> /dev/sda
  16. l-wx------. 1 root root 64 May 20 10:46 1 -> /dev/null
  17. lrwx------. 1 root root 64 May 20 10:46 2 -> /dev/pts/

在另外一个终端打开vim进程

  1. [root@centos72 ~]# vim f1

如果是vim进程就会打开交换文件

如果正常退出此文件就没有了,异常退出就会有此文件要手动删除

  1. [root@centos72 ~]# pstree -p
  2. systemd(1)─┬─NetworkManager(557)─┬─{NetworkManager}(594)
  3. └─{NetworkManager}(596)
  4. ├─VGAuthService(546)
  5. ├─agetty(573)
  6. ├─auditd(517)───{auditd}(518)
  7. ├─crond(567)
  8. ├─dbus-daemon(550)───{dbus-daemon}(556)
  9. ├─irqbalance(549)
  10. ├─master(873)─┬─pickup(1594)
  11. └─qmgr(875)
  12. ├─polkitd(540)─┬─{polkitd}(576)
  13. ├─{polkitd}(577)
  14. ├─{polkitd}(582)
  15. ├─{polkitd}(586)
  16. └─{polkitd}(587)
  17. ├─rsyslogd(791)─┬─{rsyslogd}(793)
  18. └─{rsyslogd}(794)
  19. ├─sshd(788)─┬─sshd(1076)───bash(1081)───vim(1840)
  20. └─sshd(1599)───bash(1603)───pstree(1841)
  21. ├─systemd-journal(356)
  22. ├─systemd-logind(543)
  23. ├─systemd-udevd(390)
  24. ├─tuned(789)─┬─{tuned}(1030)
  25. ├─{tuned}(1031)
  26. ├─{tuned}(1032)
  27. └─{tuned}(1046)
  28. └─vmtoolsd(547)───{vmtoolsd}(579)
  29. [root@centos72 ~]# ls /proc/1840/fd
  30. 0 1 2 4
  31. [root@centos72 ~]# ls /proc/1840/fd -al
  32. total 0
  33. dr-x------. 2 root root 0 May 20 10:53 .
  34. dr-xr-xr-x. 9 root root 0 May 20 10:53 ..
  35. lrwx------. 1 root root 64 May 20 10:53 0 -> /dev/pts/1
  36. lrwx------. 1 root root 64 May 20 10:53 1 -> /dev/pts/1
  37. lrwx------. 1 root root 64 May 20 10:53 2 -> /dev/pts/1
  38. lrwx------. 1 root root 64 May 20 10:53 4 -> /root/.f1.swp

Linux进程管理——查看内存的工具的更多相关文章

  1. linux 进程管理和内存分配

    1.进程相关概念 进程:正在运行中的程序 内核功用:进程管理.文件系统.网络功能.内存管理.驱动程序.安全功能等 Process:运行中的程序的一个副本,是被载入内存的一个指令集合 进程 ID(Pro ...

  2. Linux进程管理四大工具ps \dstat\ top\ htop

    Linux进程管理之“四大名捕” 一.四大名捕 四大名捕,最初出现于温瑞安创作的武侠小说,是朝廷中正义力量诸葛小花的四大徒弟,四人各怀绝技,分别是轻功暗器高手“无情”.内功卓越的高手“铁手”.腿功惊人 ...

  3. Linux进程管理工具vmstat,iostat,pmap

    一查看内存的工具——vmstat (一)vmstat的介绍 vmstat vmstat是Virtual Memory Statistics(虚拟内存统计)的缩写 利用vmstat命令可以对操作系统的报 ...

  4. Linux进程管理工具Supervisor的安装配置

    目录 Linux进程管理工具Supervisor的安装配置 简介 安装Python包管理工具 安装Supervisor 配置 配置文件参数说明 配置进程管理 启动supervisor 控制进程 交互终 ...

  5. Linux进程管理工具

    Linux进程管理工具 Htop yum install htop 参考帮助: http://blog.csdn.net/skh2015java/article/details/53173896 Li ...

  6. Linux 进程管理 笔记

    https://www.ibm.com/developerworks/cn/linux/l-linux-process-management/index.htmlLinux 进程管理剖析 进程可以是短 ...

  7. linux进程管理(二)

    接上[linux进程管理(一)] 终止进程的工具 kill .killall.pkill 终止一个进程或终止一个正在运行的程序,一般是通过 kill .killall.pkill.xkill 等进行. ...

  8. Linux进程管理之ps的使用

    主题Linux进程管理之ps工具的使用 一ps工具的介绍 ps: process state  进程状态ps - report a snapshot of the current processesL ...

  9. 12个Linux进程管理命令介绍(转)

    12个Linux进程管理命令介绍 [日期:2015-06-02] 来源:Linux中国  作者:Linux [字体:大 中 小]   执行中的程序在称作进程.当程序以可执行文件存放在存储中,并且运行的 ...

随机推荐

  1. 音悦台 api分析

    用户订阅MV更新 http://uapi.yinyuetai.com/i/flw/subscribe-video-list?page=1&pageSize=200&uid=XXXXXX ...

  2. java 将MySql数据库中的数据(某一列)取出放入数组中 转

    转:http://blog.csdn.net/ewili/article/details/8605638 假设mysql中test数据库中有个表式score,有数据,我只取第一列的数据出来: publ ...

  3. 牛客网暑期ACM多校训练营(第五场) F - take —— 期望+树状数组+逆元

    看到一篇好的博客特意转出来观摩大佬:转:https://blog.csdn.net/greybtfly/article/details/81413526 题目大意:给n个箱子排成一排,从头到尾按顺序依 ...

  4. PHP常用工具函数之手机号相关

    1.手机号正确与否判定 //测试手机号 $phone = '17777777777'; $pattern = '/^1[356789]\d{9}$/'; $is = preg_match($patte ...

  5. day32—CSS多列布局学习

    转行学开发,代码100天——2018-04-17 关于多列布局,前期已经梳理过,今天的培训课程学习中再次提及,趁此也做个总结和检验. 多列布局的介绍参考: day08—css布局解决方案之多列布局   ...

  6. day11—前端学习之我不想看书

    转行学开发,代码100天——2018-03-27 今天是前端学习,博客记录见证的第11天,按理说还要继续写一写代码相关的内容. 但由于今天的代码实践都是一些基础知识,还是想谈一谈关于编程方面看书的事情 ...

  7. python实现堆栈与队列的方法

    python实现堆栈与队列的方法 本文实例讲述了python实现堆栈与队列的方法.分享给大家供大家参考.具体分析如下: 1.python实现堆栈,可先将Stack类写入文件stack.py,在其它程序 ...

  8. error LNK2019: unresolved external symbol __vsnwprintf

    老DX SDK,新VS2019问题,编译老项目GG,依赖库加入 legacy_stdio_definitions.lib 解决

  9. linux下shell显示git当前分支

    function git-branch-name { git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 } functio ...

  10. Pandas案例--人口密度分析

    需求: 导入文件,查看原始数据 将人口数据和各州简称数据进行合并 将合并的数据中重复的abbreviation列进行删除 查看存在缺失数据的列 找到有哪些state/region使得state的值为N ...