动态查看一个进程的内存使用
top命令 top -d 1 -p pid [,pid ...] //设置为delay 1s,默认是delay 3s 如果想根据内存使用量进行排序,可以shift + m(Sort by memory usage)
静态查看一个进程的内存使用
1、pmap命令 pmap pid 2、ps命令 ps aux|grep process_name 3、查看/proc/process_id/文件夹下的status文件 Name: php State: R (running) SleepAVG: 0% Tgid: 21574 Pid: 21574 PPid: 10005 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 100 100 100 100 FDSize: 256 Groups: 16 100 VmPeak: 161740 kB VmSize: 161740 kB VmLck: 0 kB VmHWM: 107144 kB VmRSS: 107144 kB VmData: 106192 kB VmStk: 84 kB VmExe: 5588 kB VmLib: 7884 kB VmPTE: 268 kB Threads: 1 SigQ: 0/69632 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000001000 SigCgt: 00000001818040a7 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 Cpus_allowed: 00000000,00000000,00000000,0000000f Mems_allowed: 1 任务虚拟地址空间的大小 VmSize 应用程序正在使用的物理内存的大小 VmRSS
top 内容解释
内容解释: PID:进程的ID USER:进程所有者 PR:进程的优先级别,越小越优先被执行 NInice:值 VIRT:进程占用的虚拟内存 RES:进程占用的物理内存 SHR:进程使用的共享内存 S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数 %CPU:进程占用CPU的使用率 %MEM:进程使用的物理内存和总内存的百分比 TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。 COMMAND:进程启动命令名称
n: %MEM -- Memory usage (RES) A task's currently used share of available physical memory. o: VIRT -- Virtual Image (kb) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.) VIRT = SWAP + RES. p: SWAP -- Swapped size (kb) The swapped out portion of a task's total virtual memory image. q: RES -- Resident size (kb) The non-swapped physical memory a task has used. RES = CODE + DATA. r: CODE -- Code size (kb) The amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS. s: DATA -- Data+Stack size (kb) The amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS. t: SHR -- Shared Mem size (kb) The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes. |