Retrieve CPU usage and memory usage of a single pr

2019-01-08 03:30发布

I want to get the CPU and memory usage of a single process on Linux - I know the PID. Hopefully, I can get it every second and write it to a CSV using the 'watch' command. What command can I use to get this info from the Linux command-line?

16条回答
啃猪蹄的小仙女
2楼-- · 2019-01-08 03:30

You could use top -b and grep out the pid you want (with the -b flag top runs in batch mode), or also use the -p flag and specify the pid without using grep.

查看更多
你好瞎i
3楼-- · 2019-01-08 03:33

Above list out the top cpu and memory consuming process

        ps axo %cpu,%mem,command | sort -nr | head
查看更多
何必那么认真
4楼-- · 2019-01-08 03:37

ps command (should not use):

top command (should use):

Use top to get CPU usage in real time(current short interval):

top -b -n 2 -d 0.2 -p 6962 | tail -1 | awk '{print $9}'

will echo like: 78.6

查看更多
Bombasti
5楼-- · 2019-01-08 03:39

To get the memory usage of just your application (as opposed to the shared libraries it uses, you need to use the Linux smaps interface). This answer explains it well.

查看更多
贼婆χ
6楼-- · 2019-01-08 03:41
ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr

or per process

ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr |grep mysql
查看更多
走好不送
7楼-- · 2019-01-08 03:41

CPU and memory usage of a single process on Linux or you can get the top 10 cpu utilized processes by using below command

ps -aux --sort -pcpu | head -n 11

查看更多
登录 后发表回答