Retrieve CPU usage and memory usage of a single process on Linux?

前端 未结 21 2000
抹茶落季
抹茶落季 2020-11-27 09:00

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

21条回答
  •  天命终不由人
    2020-11-27 09:35

    As commented in caf's answer above, ps and in some cases pidstat will give you the lifetime average of the pCPU. To get more accurate results use top. If you need to run top once you can run:

    top -b -n 1 -p 
    

    or for process only data and header:

    top -b -n 1 -p  | tail -3 | head -2
    

    without headers:

    top -b -n 1 -p  | tail -2 | head -1
    

提交回复
热议问题