通过proc/procid/status查看进程内存
piky@piky-WRT-WX9:~/src/test$ cat /proc/3118/status
Name: a.out
Umask: 0002
State: S (sleeping)
Tgid: 3118
Ngid: 0
Pid: 3118
PPid: 1832
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
FDSize: 256
Groups: 4 24 27 30 46 107 122 131 132 1000
NStgid: 3118
NSpid: 3118
NSpgid: 3118
NSsid: 1832
VmPeak: 33160 kB //峰值内存
VmSize: 33160 kB //进程虚拟地址空间大小
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 31900 kB //正在使用的物理内存大小
VmRSS: 31900 kB
RssAnon: 30652 kB
RssFile: 1248 kB
RssShmem: 0 kB
VmData: 29976 kB //进程数据段大小
VmStk: 1016 kB //用户态栈大小
VmExe: 4 kB // 代码段大小
VmLib: 1616 kB // 库映射到虚拟内存空间的大小
VmPTE: 104 kB // 进程页表大小
VmSwap: 0 kB
HugetlbPages: 0 kB
CoreDumping: 0
THP_enabled: 1
Threads: 1
SigQ: 0/30527
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Seccomp_filters: 0
Speculation_Store_Bypass: thread vulnerable
SpeculationIndirectBranch: conditional enabled
Cpus_allowed: ff
Cpus_allowed_list: 0-7
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 775
nonvoluntary_ctxt_switches: 1
通过smaps查看内存
piky@piky-WRT-WX9:~/src/test$ cat /proc/3118/smaps | grep '^Pss:' | awk '{sum += $2} END {print sum}'
30879
通过ps查看
piky@piky-WRT-WX9:~/src/test$ ps -aux | grep a.out
piky 3118 0.0 0.4 33160 31900 pts/0 S+ 20:01 0:00 ./a.out-----进程内存
查看整机内存
piky@piky-WRT-WX9:~/src/test$ cat /proc/meminfo
MemTotal: 7882088 kB
MemFree: 4413984 kB
MemAvailable: 6254932 kB
Buffers: 62028 kB
Cached: 2279764 kB
SwapCached: 0 kB
Active: 1007364 kB
Inactive: 1897292 kB
Active(anon): 2100 kB
Inactive(anon): 877468 kB
Active(file): 1005264 kB
Inactive(file): 1019824 kB
Unevictable: 289624 kB
Mlocked: 64 kB
SwapTotal: 15999996 kB
SwapFree: 15999996 kB
Dirty: 8 kB
Writeback: 0 kB
AnonPages: 852580 kB
Mapped: 407612 kB
Shmem: 316708 kB
KReclaimable: 82808 kB
Slab: 168188 kB
SReclaimable: 82808 kB
SUnreclaim: 85380 kB
KernelStack: 9184 kB
PageTables: 21644 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 19941040 kB
Committed_AS: 4914756 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 34800 kB
VmallocChunk: 0 kB
Percpu: 6784 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 215740 kB
DirectMap2M: 5822464 kB
DirectMap1G: 3145728 kB