码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Linux:在Linux中查看进程占用内存大小的方法


         在开发和运维过程中,经常会遇到的问题是一个进程到底占用了多大的内存。以下通过常用的2个命令来说明如何获取进程占用的内存

    比如有一个java进程,它的pid=7020

    $ps -ef | grep LogAgent | grep ^grep
    usrapp 7020 1 0 15:23 ? 00:00:02 java -jar LogAgent.jar

    1、使用ps

    $ps -o vsz,rss,sz,size,pid -q7020
    VSZ        RSS    SZ         SIZE        PID
    4444604 39160 1111151 4268292 7020
    以上显示的数字的单位是KB ,其中vsz,rss,sz,size的含义如下:
    namedescription
    vsz

    virtual memory size of the process in KiB (1024-byte units).  Device mappings are currently excluded; this is subject to change.  (alias vsize).

    rss

    resident set size, the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize, rsz).

    sz

    size in physical pages of the core image of the process.  This includes text, data, and stack space.  Device mappings are currently excluded; this is subject to change.  See vsz and rss.

    sizeapproximate amount of swap space that would be required if the process were to dirty all writable pages and then be swapped out. This number is very rough!

     

    其中最关注的是RSS,它是实际占用的物理内存的大小。

    2、使用top

    $top -n 1 -p 7020
    top - 16:29:32 up 166 days, 5:59, 3 users, load average: 0.25, 0.31, 0.48
    Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
    %Cpu(s): 0.0 us, 3.4 sy, 0.0 ni, 96.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
    KiB Mem : 7388532 total, 158576 free, 5822636 used, 1407320 buff/cache
    KiB Swap: 16777212 total, 12173780 free, 4603432 used. 1012880 avail Mem
    PID  USER  PR NI VIRT      RES    SHR   S %CPU %MEM TIME+  COMMAND
    7020 usrapp 20 0  4444604 39160 12444 S 0.0       0.5       0:02.15 java
    从执行结果可以看到:
    ps. VSZ=top.VIRT
    ps. RSS=top.RES

     参考文档

    ps(1) - Linux manual page

    top(1) - Linux manual page

  • 相关阅读:
    9月1日,开学快乐!新的学期,新的开始!
    使用clip-path来画不同的形状,三角形,多边形,菱形,六边形等等
    顺序表第一部分(介绍篇),三部曲后面分别是实现和介绍
    单例模式--饿汉模式, 懒汉模式
    SpringCloud之Gateway整合Sentinel服务降级和限流
    华为设备配置攻击溯源命令
    【GCN-RS】MCL: Mixed-Centric Loss for Collaborative Filtering (WWW‘22)
    ChatGPT 助力英文论文翻译和润色
    都说自己是数据分析师,80%分析结果都是失败的,小心被裁了
    React 组件的3大属性: state
  • 原文地址:https://blog.csdn.net/netyeaxi/article/details/132858066
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号