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

前端 未结 21 1914
抹茶落季
抹茶落季 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:49

    The following command gets the average of CPU and memory usage every 40 seconds for a specific process(pid)

    pidstat 40 -ru -p 
    

    Output for my case(first two lines for CPU usage, second two lines for memory):

    02:15:07 PM       PID    %usr %system  %guest    %CPU   CPU  Command
    02:15:47 PM     24563    0.65    0.07    0.00    0.73     3  java
    
    02:15:07 PM       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
    02:15:47 PM     24563      6.95      0.00 13047972 2123268   6.52  java
    

提交回复
热议问题