Linux 统计当前所有进程使用swap分区的情况

上传人:ji****72 文档编号:37521976 上传时间:2018-04-17 格式:DOCX 页数:6 大小:335.83KB
返回 下载 相关 举报
Linux 统计当前所有进程使用swap分区的情况_第1页
第1页 / 共6页
Linux 统计当前所有进程使用swap分区的情况_第2页
第2页 / 共6页
Linux 统计当前所有进程使用swap分区的情况_第3页
第3页 / 共6页
Linux 统计当前所有进程使用swap分区的情况_第4页
第4页 / 共6页
Linux 统计当前所有进程使用swap分区的情况_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《Linux 统计当前所有进程使用swap分区的情况》由会员分享,可在线阅读,更多相关《Linux 统计当前所有进程使用swap分区的情况(6页珍藏版)》请在金锄头文库上搜索。

1、Linux 统计当前所有进程使用 swap 分区的情况前言若操作系统的物理内存用完了,则就会用到 swap(虚拟内存)。系统就会跑得 很慢,但仍能运行;如果 swap 分区用完了,那么系统就会发生错误。通常会出 现“Application is out of memory”的错误,严重时会造成服务进程的死锁。 操作系统无法正常运行,所以我们要高度重视内存使用,下面我们就来说一说, 怎么统计哪些进程使用了 swap 分区,查看 swap 的方法有许多,下面我们就来 一个个说明!1. free 命令free m 命令中只能查看当前 swap 分区的使用情况,但不能查看具体哪些进 程使用了 swap

2、!2. top 命令CentOS 5.5 (top)top 命令能查看 swap 总量和使用情况,我们还可以使用快捷键查看,top+f+p 来查看!并不是实际的使用 swap,而是 VIRT-RES 得来的,就是虚拟内存中所使用过的 swap 部分,并不能得到我们想要的结果!CentOS 6.0-6.4 (top)这样就明显看出是取出的每个进程的 swap,能很方便的查看哪些进程使用了 swap。从中也能看到一个信息,那就是读取了/proc/#/status !3. vmstat 命令vmstat 也不能查看哪个进程使用了 swap,我们只能看到,swap - si 与 so, 下面我们简单说

3、明一下!Memory(内存):swpd: 使用虚拟内存大小free: 可用内存大小buff: 用作缓冲的内存大小cache: 用作缓存的内存大小Swap (虚拟内存):si: 每秒从交换区读到内存的大小so: 每秒写入交换区的内存大小4. shell 查看在 Linux 内核 2.6.16 中引入了一个系统内存接口特性,这个接口位于 /proc/$pid/目录下的 smaps 文件中 ,一看内容发现是进程内存映像信息,比 同一目录下的 maps 文件更详细些!rootlocalhost # cat /proc/1/smaps下面我们简单说明一下 samps 里面的内容,00400000-004

4、09000 是该虚拟内存段的开始和结束位置r-xp 内存段的权限,rw 是指可读写,x 是指可执行,p 是指私有, 如果是 s 则为共享00000000 该虚拟内存段在对应的映射文件中的偏移量08:02 文件的主设备和次设备号1361644 被映射到虚拟内存的文件的索引节点号/sbin/init 被映射到虚拟内存的文件名称Size 是进程使用内存空间,并不一定实际分配了内存(VSS)Rss 是实际分配的内存Shared_Clean 和其他进程共享的未改写页面Shared_Dirty 和其他进程共享的已改写页面Private_Clean 未改写的私有页面页面Private_Dirty 已改写的私

5、有页面页面Swap 存在于交换分区的数据大小(如果物理内存有限,可能存在 一部分在主存一部分在交换分区)Pss 是平摊计算后的使用内存(有些内存会和其他进程共享,例如 mmap 进来的)通过 cat /proc/$(pid)/smaps 能查看所有进程的使用情况,若你想要查看某 个进程所使用的 swap 只需要,awk /Swap:/ SWAP+=$2ENDprint SWAP“ KB“ /proc/$(pid)/smaps5. shell 脚本统计#!/bin/bash # function getswap SUM=0 OVERALL=0 for DIR in find /proc/ -ma

6、xdepth 1 -type d | egrep “/proc/0-9“ ; do PID=echo $DIR | cut -d / -f 3 PROGNAME=ps -p $PID -o comm -no-headers for SWAP in grep Swap $DIR/smaps 2/dev/null| awk print $2 do let SUM=$SUM+$SWAP done echo “PID=$PID - Swap used: $SUM - ($PROGNAME )“ let OVERALL=$OVERALL+$SUM SUM=0 done echo “Overall swa

7、p used: $OVERALL“ getswap效果:rootlocalhost # sh getswap.sh PID=1 - Swap used: 76 - (init ) PID=2 - Swap used: 0 - (migration/0 ) PID=3 - Swap used: 0 - (ksoftirqd/0 ) PID=4 - Swap used: 0 - (events/0 ) PID=5 - Swap used: 0 - (khelper ) PID=7 - Swap used: 0 - (kthread ) PID=11 - Swap used: 0 - (kblock

8、d/0 ) PID=12 - Swap used: 0 - (kacpid ) PID=177 - Swap used: 0 - (cqueue/0 ) PID=180 - Swap used: 0 - (khubd ) PID=182 - Swap used: 0 - (kseriod ) PID=250 - Swap used: 0 - (khungtaskd ) PID=251 - Swap used: 0 - (pdflush ) PID=252 - Swap used: 0 - (pdflush ) PID=253 - Swap used: 0 - (kswapd0 ) PID=25

9、4 - Swap used: 0 - (aio/0 ) PID=460 - Swap used: 0 - (kpsmoused )PID=490 - Swap used: 0 - (mpt_poll_0 ) PID=491 - Swap used: 0 - (mpt/0 ) PID=492 - Swap used: 0 - (scsi_eh_0 ) PID=495 - Swap used: 0 - (ata/0 ) PID=496 - Swap used: 0 - (ata_aux ) PID=503 - Swap used: 0 - (kstriped ) PID=512 - Swap us

10、ed: 0 - (kjournald ) PID=537 - Swap used: 0 - (kauditd ) PID=570 - Swap used: 460 - (udevd ) PID=1827 - Swap used: 0 - (kmpathd/0 ) PID=1828 - Swap used: 0 - (kmpath_handlerd ) PID=1889 - Swap used: 0 - (kjournald ) PID=1891 - Swap used: 0 - (kjournald ) PID=2361 - Swap used: 512 - (dhclient ) PID=2

11、420 - Swap used: 228 - (auditd ) PID=2422 - Swap used: 128 - (audispd ) PID=2452 - Swap used: 16 - (syslogd ) PID=2456 - Swap used: 84 - (klogd ) PID=2535 - Swap used: 120 - (portmap ) PID=2565 - Swap used: 0 - (rpciod/0 ) PID=2571 - Swap used: 140 - (rpc.statd ) PID=2603 - Swap used: 464 - (rpc.idm

12、apd ) PID=2626 - Swap used: 368 - (dbus-daemon ) PID=2639 - Swap used: 128 - (hcid ) PID=2643 - Swap used: 100 - (sdpd ) PID=2664 - Swap used: 0 - (krfcommd ) PID=2707 - Swap used: 656 - (pcscd ) PID=2721 - Swap used: 104 - (acpid ) PID=2735 - Swap used: 2196 - (hald ) PID=2736 - Swap used: 184 - (h

13、ald-runner ) PID=2745 - Swap used: 112 - (hald-addon-acpi ) PID=2756 - Swap used: 116 - (hald-addon-keyb ) PID=2765 - Swap used: 84 - (hald-addon-stor ) PID=2789 - Swap used: 104 - (hidd ) PID=2813 - Swap used: 260 - (automount ) PID=2849 - Swap used: 564 - (sshd ) PID=2862 - Swap used: 768 - (cupsd

14、 ) PID=2906 - Swap used: 1108 - (sendmail ) PID=2914 - Swap used: 1144 - (sendmail ) PID=2928 - Swap used: 80 - (gpm ) PID=2941 - Swap used: 508 - (crond ) PID=2964 - Swap used: 276 - (xfs ) PID=2989 - Swap used: 104 - (atd ) PID=3015 - Swap used: 80 - (avahi-daemon )PID=3016 - Swap used: 156 - (ava

15、hi-daemon ) PID=3044 - Swap used: 200 - (smartd ) PID=3047 - Swap used: 320 - (login ) PID=3048 - Swap used: 68 - (mingetty ) PID=3049 - Swap used: 72 - (mingetty ) PID=3050 - Swap used: 68 - (mingetty ) PID=3051 - Swap used: 68 - (mingetty ) PID=3052 - Swap used: 72 - (mingetty ) PID=3103 - Swap us

16、ed: 15148 - (yum-updatesd ) PID=3105 - Swap used: 160 - (gam_server ) PID=3106 - Swap used: 416 - (bash ) PID=3215 - Swap used: 728 - (sshd ) PID=3217 - Swap used: 356 - (bash ) PID=3249 - Swap used: 728 - (sshd ) PID=3251 - Swap used: 356 - (bash ) PID=3280 - Swap used: 616 - (sshd ) PID=3282 - Swap used: 140 - (bash ) PID=11634 - Swap used: 0 - (sh ) PID=11635 - Swap used: 0 - ( ) PID=11636 - Swap used: 0 - ( ) PID=11637 - Swap use

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号