美文网首页
Linux查看Swap内存使用情况

Linux查看Swap内存使用情况

作者: 潘猛_9f76 | 来源:发表于2020-09-23 13:34 被阅读0次

    查看指定进程swap使用情况

    # cat /proc/3315/smaps   | grep Swap  | more
    Swap:                  0 kB
    SwapPss:               0 kB
    Swap:                  4 kB
    SwapPss:               4 kB
    

    编写脚本getswap.sh,查看所有进程的swap,并排序

    echo -e "pid\tswap\tproc_name"
    for pid in $(ls -l /proc | grep ^d | awk '{ print $9 }'| grep  -v [^0-9]); do
        # 判断改进程是否占用了swap
        grep -q "Swap" /proc/$pid/smaps 2>/dev/null
        if [ $? -eq 0 ];then
        # 如果占用了swap
            swap=$(grep Swap /proc/$pid/smaps | gawk '{ sum+=$2;} END { print sum }')
            proc_name=$(ps aux | grep -w "$pid" | grep -v grep  | awk '{ for(i=11;i<=NF;i++){ printf("%s ",$i); }}')
            if [ $swap -gt 0 ];then
            # 输出swap信息
                echo -e "$pid\t${swap} KB\t$proc_name"
            fi
        fi
        done | sort -k2 -n
    

    查看结果

     # sh getswap.sh
    pid     swap    proc_name
    1019    8 KB    /usr/bin/VGAuthService -s
    27855   8 KB    sshd: root@pts/1
    27979   48 KB   sshd: root@notty
    1026    224 KB  /usr/sbin/NetworkManager --no-daemon
    1259    236 KB  (sd-pam)
    3315    280 KB  /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512 -oGSSAPIKexAlgorithms=gss-gex-sha1-,gss-group14-sha1- -oKexAlgorithms=curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1 -oHostKeyAlgorithms=rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com -oPubkeyAcceptedKeyTypes=rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com -oCASignatureAlgorithms=rsa-sha2-256,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,rsa-sha2-512,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa
    1042    1160 KB /usr/libexec/platform-python -Es /usr/sbin/tuned -l -P
    3322    6108 KB /usr/sbin/rsyslogd -n
    773     6108 KB /usr/lib/systemd/systemd-journald
    
    
    

    相关文章

      网友评论

          本文标题:Linux查看Swap内存使用情况

          本文链接:https://www.haomeiwen.com/subject/dznnyktx.html