Getting CPU utilization and memory for a process

I am trying to get cpu util and memory occupied for a process. I use these (I am showing output also):

using top
----------
$ top p 25272 d 5
top - 01:52:17 up 2 days, 21:28, 2 users, load average: 0.02, 0.05, 0.06
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.1% hi, 0.0% si
Mem: 4147560k total, 1628824k used, 2518736k free, 37320k buffers
Swap: 0k total, 0k used, 0k free, 244200k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25272 911 16 0 1431m 1.1g 22m S 0.0 28.3 131:51.55 java

using ps
----------
$ ps -p 25272 u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
911 25272 50.3 28.3 1465912 1175352 ? S Mar01 131:51 /usr/java/jre-1

Question - why does these 2 programs show different utilization for the same process ? ps is showing 50.0 % whereas top is showing 0.0 %.

top averages cpu over time - ps takes a snapshot at the instant it runs. Overall, the value from top is more useful.

Depending on your OS there may be other, and maybe more useful means of getting what you want.

I am not happy with the answer - even top command seems to be a snapshot of the process(es) as per manual for top.

But then Jim added: Depending of your OS... What OS are we dealing with?

It is red hat Linux (Red Hat Enterprise Linux AS release 4, Nahant Update 5 as per cat /etc/redhat-release command)

I dont know RH... but I suppose all unix have vmstat/sar command
do a man of sar to find the correct syntax for your usage

All the best