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
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