Reputation: 481
I want to find CPU usage of my own c application. I have already use ps -p pid -o %cpu,%mem,cmd It works fine in my Ubuntu 10.04 desktop. But not work in ARM architecture.
It shows following error.
ps: invalid option -- 'p'
BusyBox v1.13.2 (2011-03-24 18:58:44 CDT) multi-call binary
Usage: ps
Report process status
Options: w Wide output
So I need c code for finding cpu usage.
Upvotes: 2
Views: 555
Reputation: 3541
If you want to measure CPU time and if you're on a (mostly) POSIX-supporting platform (maybe Android?), then you should look at clock_gettime()
and getrusage()
. You can find something to start here.
Upvotes: 0
Reputation: 1412
Busybox also provides "top", which can display the CPU usage of processes.
This doesn't directly answer your question since it's not using C, but maybe it will solve your problem without the extra hassle since you were already willing to use ps.
Upvotes: 1
Reputation: 1168
Busybox is a small footprint set of tools which only contains the most useful subset of the functionality you will find in a desktop system.
For a more complete ps you might want to use the ps from http://procps.sourceforge.net/
You might want to replace the ps in busybox, or you could take snippets of C source from procps if your program has a GPL compatible license.
Upvotes: 1