1.命令行输入top回车,然后按下大写M按照memory排序,按下大写P按照CPU排序。
2. ps -ef | grep "进程名"
ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep 进程名
例如:
# ps -ef | grep mongodb | grep -v grep
root 18512 1 8 Feb28 ? 11:25:23 mongod -f mongodb.conf
# ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep 18512 | grep -v grep
18512 mongod mongod -f mongodb.conf 8.0 6243952 7924496 Feb28 root 0
备注:
pid:进程的ID
vsz:进程占用的虚拟内存
rsz:进程占用的物理内存
3. top -d 1 -p pid
例如:
# top -d 1 -p 18512
top - 13:18:41 up 9 days, 19:53, 3 users, load average: 0.00, 0.00, 0.00
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 8191244k total, 7929432k used, 261812k free, 122160k buffers
Swap: 20479996k total, 16232k used, 20463764k free, 1316248k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18512 root 20 0 7738m 6.0g 5472 S 1.0 76.3 685:26.98 mongod
4. pmap -x pid
例如:
# pmap -x 18512