美文网首页
03-统计内存

03-统计内存

作者: 数据工程师从入门到放弃 | 来源:发表于2019-06-19 01:17 被阅读0次

题目要求

写一个脚本计算一下linux系统所有进程占用内存大小的和。

xuehaozhe@ubuntu:~/shell$ free
              total        used        free      shared  buff/cache   available
Mem:        2030464      806448      154792        8484     1069224      975332
Swap:       2094076      342572     1751504

  
----------
xuehaozhe@ubuntu:~/shell$ ps aux |head
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.2 185164  5704 ?        Ss   Jun17   0:21 /lib/systemd/systemd --system --deserialize 29
root          2  0.0  0.0      0     0 ?        S    Jun17   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    Jun17   0:01 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   Jun17   0:00 [kworker/0:0H]
root          7  0.0  0.0      0     0 ?        S    Jun17   0:23 [rcu_sched]
root          8  0.0  0.0      0     0 ?        S    Jun17   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        S    Jun17   0:00 [migration/0]
root         10  0.0  0.0      0     0 ?        S    Jun17   0:00 [watchdog/0]
root         11  0.0  0.0      0     0 ?        S    Jun17   0:00 [watchdog/1]
  
xuehaozhe@ubuntu:~/shell$ ps aux |grep -v 'TIME COMMAND'|head 过滤掉第一行
xuehaozhe@ubuntu:~/shell$ ps aux |sed '1d' |head

root          1  0.0  0.2 185164  5704 ?        Ss   Jun17   0:21 /lib/systemd/systemd --system --deserialize 29
root          2  0.0  0.0      0     0 ?        S    Jun17   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    Jun17   0:01 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   Jun17   0:00 [kworker/0:0H]
root          7  0.0  0.0      0     0 ?        S    Jun17   0:23 [rcu_sched]
root          8  0.0  0.0      0     0 ?        S    Jun17   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        S    Jun17   0:00 [migration/0]
root         10  0.0  0.0      0     0 ?        S    Jun17   0:00 [watchdog/0]
root         11  0.0  0.0      0     0 ?        S    Jun17   0:00 [watchdog/1]
root         12  0.0  0.0      0     0 ?        S    Jun17   0:00 [migration/1]
  
  
#!/bin/bash
sum=0
for n in `ps aux |grep -v 'TIME COMMAND'|awk '{print $6}'`
do
    sum=$[$sum+$n]
done
echo $sum

相关文章

  • 03-统计内存

    题目要求 写一个脚本计算一下linux系统所有进程占用内存大小的和。

  • 性能优化03-内存优化

    性能优化03-内存优化 一、内存模型 Java内存模型:Java程序在运行时内存的模型。而Java代码是运行在Ja...

  • 03-内存分页

    1、写作背景 懒惰象生锈一样,比操劳更能消耗身体。 2、参考网址 3、学习目的 记录工具类进行内存分页 4、核心操...

  • 我的学习笔记汇总(索引)

    汇编语言入门 01-电脑基础知识 02-CPU工作原理 03-内存访问 04-开始汇编编程 05-更加灵活的内存访...

  • linux下统计进程所占内存

    实时统计程序所占内存情况,查内存泄漏用

  • Redis内存模型

    一、Redis内存统计 工欲善其事必先利其器,在说明Redis内存之前首先说明如何统计Redis使用内存的情况。 ...

  • 第8章 理解内存

    理解Redis内存消耗,管理和优化。 1. 内存消耗 1.1 内存使用统计 通过info memory命令获取内存...

  • Redis 的内存模型

    Redis 内存统计 查看内存: used_memory : Redis 分配器分配的内存总量used_memor...

  • OC底层原理04-OC对象内存优化

    本文将结合我的另外一篇文章 Object-C底层原理03-结构体内存对齐[https://www.jianshu....

  • Redis学习--理解内存

    内存消耗 内存使用统计info memory info memory详细解释 当mem_fragmentation...

网友评论

      本文标题:03-统计内存

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