The ps command allows you to specify options as to which metrics you want as well as to specify which process to show with the -p flag. You can use the h flag to suppress print of the header.
So:
Code:
while true; do ps h -p<pid> -o pid,ppid,user,group,%cpu,%mem,rss,sz,vsz,cmd ; sleep 5; done
Where <pid> is the process ID in which you're interested.
This is standard ps command but instead of using default "-ef" you specify
the options you want with "-o". As noted the h suppresses the header.
The options are separated by comma. The options shown above are:
pid Process ID number
ppid Parent process ID number
user Effective user name (owner of the process)
group Effective group name (group of the process)
%cpu Percent of CPU utilization
%mem Percent of memory utilization
rss Resident Set Size
sz Size in physical pages of the core image.
vsz Virtual memory size
cmd The command and its arguments. Putting it last in options gives full details. Putting it anywhere else in options gives an abbreviated output.
You can of course use only the %cpu and %mem to get those two basic metrics you requested.
You can also change the sleep to a number greater than 5 (seconds) depending on what measurement interval you wish. Do NOT eliminate the sleep entirely as it will kill your CPU.