* CPU/disk usage
@ 2005-05-21 14:09 Adam Dyga
2005-05-21 20:27 ` Glynn Clements
0 siblings, 1 reply; 3+ messages in thread
From: Adam Dyga @ 2005-05-21 14:09 UTC (permalink / raw)
To: linux-c-programming
Hello,
What's the best way to:
1. Get the percent cpu usage (as in top)
2. Get disk activity (eg. number of bytes read/written from/to disk
during some period of time).
Ad1) I know I could find the cpu usage in top sources, but unfortunately
I don't have enough time
to do it currently - maybe some of you did this already.
There is sysinfo() system call that returns average loads during the
last 1, 5, and 15
minutes but average load, AFAIK, is a average number of tasks waiting
for cpu, so it's not
exactly what I want.
Cheers
AD
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: CPU/disk usage
@ 2005-05-21 17:12 Akbar Ali
0 siblings, 0 replies; 3+ messages in thread
From: Akbar Ali @ 2005-05-21 17:12 UTC (permalink / raw)
To: Adam Dyga, linux-c-programming
Why not just take a quick look at the top source code
?
btw, if you find out tell me, cause i'm intersted in
that data as well..
--- Adam Dyga <adeon@tlen.pl> wrote:
> Hello,
>
> What's the best way to:
> 1. Get the percent cpu usage (as in top)
> 2. Get disk activity (eg. number of bytes
> read/written from/to disk
> during some period of time).
>
> Ad1) I know I could find the cpu usage in top
> sources, but unfortunately
> I don't have enough time
> to do it currently - maybe some of you did this
> already.
> There is sysinfo() system call that returns average
> loads during the
> last 1, 5, and 15
> minutes but average load, AFAIK, is a average number
> of tasks waiting
> for cpu, so it's not
> exactly what I want.
>
> Cheers
> AD
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at
> http://vger.kernel.org/majordomo-info.html
>
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news and more. Check it out!
http://discover.yahoo.com/mobile.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: CPU/disk usage
2005-05-21 14:09 Adam Dyga
@ 2005-05-21 20:27 ` Glynn Clements
0 siblings, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2005-05-21 20:27 UTC (permalink / raw)
To: Adam Dyga; +Cc: linux-c-programming
Adam Dyga wrote:
> What's the best way to:
> 1. Get the percent cpu usage (as in top)
The way that ps does it is to obtain the process start time and amount
of user and system time used from /proc/<pid>/stat, and the number of
seconds since boot from /proc/uptime, then compute the CPU usage as
the ratio of the total time used (user + system) to the time the
process has been running (system uptime - process start time).
Note that this gives the average CPU usage over the lifetime of the
process. If you want a current figure, measure the change in the total
usage over a given interval and divide by the interval.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-05-21 20:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-21 17:12 CPU/disk usage Akbar Ali
-- strict thread matches above, loose matches on Subject: below --
2005-05-21 14:09 Adam Dyga
2005-05-21 20:27 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).