当前位置:首页 > linux > 正文

linux查内存占用命令

  • linux
  • 2024-04-24 08:40:49
  • 3544

1. free
free 命令显示系统中可用的、已使用的和总内存。
示例:
free -m
输出:
total used free shared buff/cache available
Mem: 7.8G 4.8G 2.9G 48M 137M 2.3G
Swap: 15.9G 0B 15.9G
2. top
top 命令实时显示系统中的进程和资源使用情况,包括内存占用。
示例:
top
输出:
top - 06:17:12 up 15:24, 2 users, load average: 0.24, 0.32, 0.34
Tasks: 234 total, 2 running, 231 sleeping, 0 stopped, 1 zombie
%Cpu(s): 1.5 us, 0.3 sy, 0.0 ni, 98.1 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem : 7976432 total, 6117920 used, 1858512 free, 128344 buffers
KiB Swap: 16378236 total, 0 used, 16378236 free. 5520824 cached Mem
在输出中,KiB Mem 行显示了内存的总大小、已使用大小、空闲大小和缓冲区大小。
3. ps
ps 命令显示正在运行的进程的信息,包括内存占用。
示例:
ps -aux --sort -rss
输出:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 8856 444 ? Ss Jan23 0:00 /usr/lib/systemd/systemd --system --deserialize 22
root 2 0.0 0.0 8672 436 ? S Jan23 0:00 /usr/lib/systemd/systemd-journald
root 4 0.0 0.0 9676 516 ? S Jan23 0:00 /usr/lib/systemd/systemd-udevd --daemon
在输出中,%MEM 列显示了每个进程使用的内存百分比,RSS 列显示了每个进程的驻留集大小(实际使用的内存大小)。
4. vmstat
vmstat 命令显示虚拟内存统计信息,包括内存占用。
示例:
vmstat 1 5
输出:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 21092 124184 148052 190952 0 0 0 0 41 231 0 0 100 0 0
0 0 21096 124184 148056 190952 0 0 0 0 41 230 0 0 100 0 0
0 0 21096 124184 148056 190952 0 0 0 0 41 229 0 0 100 0 0
0 0 21092 124180 148052 190940 0 0 0 0 40 230 0 0 100 0 0
0 0 21092 124180 148052 190940 0 0 0 0 37 230 0 0 100 0 0
在输出中,free 列显示了可用的内存大小。