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

Supertux picture Supertux · Aug 3, 2009 · Viewed 392.4k times · Source

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?

Answer

caf picture caf · Aug 3, 2009
ps -p <pid> -o %cpu,%mem,cmd

(You can leave off "cmd" but that might be helpful in debugging).

Note that this gives average CPU usage of the process over the time it has been running.