Search code examples
macosshellawkgrepps

Get Process's cpu, thread, vsize, and rsize in MAC OSX


I want to know the CPU,thread, VSize, Rsize of a process based on its PID.So i was using top -i 1 -l 1 command and grepping the corresponding values.But top differs form MAC 10.5 to 10.7 .Is there any specific way to get only those columns itself .

code process=top -i 1 -l 1 | grep "$PID" cpu=echo "$process" | awk '{print $3}'`

similarly 5 10 11 for the corresponding(thread, VSize, Rsize) values in 10.5 But the columns differs in 10.7 .

Is there any generic way to get this in shell script Please help.


Solution

  • I use this on solaris:

    ps -eo pmem,pid,pcpu,rss,vsz,time,args | sort -k 1 -r|awk '$2~/<your pid>/'