CPU usage of a process

I'm trying to monitor the CPU usage of a process and output that value to a file or variable. I know topas or nmon can tell me this in interactive mode but what I need is topas-looking output that allows me to write to a file after a discrete interval. Unlike nmon data collection to a file on top processes I want to see the CPU consumption of the process no matter what it is.

Anymore know of a method to do this? I've been searching the web and forums but haven't had luck finding anything yet.

In ksh

ps -o"%C" -p $yourPID

tells you the percentage of time the process has used the CPU since the process started.

Thanks but that unfortunately doesn't give the actual current %CPU usage. Its also further diluted by the number of available processors. So while what you suggest may give a value of 0.6% the actually current usage could be 35%. I've seen this in practice and thats my dilema.

Sorry, maybe I missunderstod you. What exactly do you mean by actual current %CPU usage?

The amount of CPU time as a percentage currently being consumed. ie what topas shows

try with :

ps aux |grep processname

return many informations