Linux中查看某個進程占用內存的情況,執行如下命令即可,將其中的[pid]替換成相應進程的PID號:
復制代碼代碼如下:
cat /proc/[pid]/status
說明
/proc/[pid]/status中所保存的信息除了內存信息,還包括進程IDs、信號等信息,此處暫時只介紹內存相關的信息。
舉例
顯示進程cron的內存信息,通過pidof cron獲取進程ID,或者通過ps -aux | grep cron查找進程ID。
復制代碼代碼如下:
$ cat /proc/1161/status
Name: cron
State: S (sleeping)
Tgid: 1161
Ngid: 0
Pid: 1161
PPid: 1
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 64
Groups: 0
VmPeak: 23792 kB
VmSize: 23656 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 1040 kB
VmRSS: 1004 kB
VmData: 260 kB
VmStk: 136 kB
VmExe: 40 kB
VmLib: 2668 kB
VmPTE: 72 kB
VmSwap: 0 kB
Threads: 1
SigQ: 0/15442
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000010001
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff
Seccomp: 0
Cpus_allowed: 3
Cpus_allowed_list: 0-1
Mems_allowed: 00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 151
nonvoluntary_ctxt_switches: 0