Thread View: comp.unix.programmer
5 messages
5 total messages
Started by Alessandro Coelho Ribeiro
Wed, 07 Aug 1996 00:00
A function to get processor load
Author: Alessandro Coelho Ribeiro
Date: Wed, 07 Aug 1996 00:00
Date: Wed, 07 Aug 1996 00:00
13 lines
1043 bytes
1043 bytes
I've been working on a program that needs to get network and processor load information. The network part, I'll try to code it by myself. But I wonder if there's a Unix system call to get these informations: 1 - Load on processor 2 - Free physical memory 3 - Free virtual memory I'm using Gnu C++ with Linux and Solaris, but I intend it to port it to other platforms as well. Thanks, Alessandro Coelho Ribeiro (sandro@cos.ufrj.br)
Re: A function to get processor load
Author: Andreas Christoph
Date: Thu, 08 Aug 1996 00:00
Date: Thu, 08 Aug 1996 00:00
30 lines
1618 bytes
1618 bytes
In article <3209432F.A49@centroin.com.br>, Alessandro Coelho Ribeiro <sandro@centroin.com.br> writes: >I've been working on a program that needs to get network and processor >load information. The network part, I'll try to code it by myself. But > I wonder if there's a Unix system call to get these informations: >1 - Load on processor >2 - Free physical memory >3 - Free virtual memory >I'm using Gnu C++ with Linux and Solaris, but I intend it to port it to >other platforms as well. > There is probably no simple system call to get this information. Under Linux however you can get this information from the /proc- filesystem. Open and read from /proc/loadavg (for 1) and /proc/meminfo (for 2 and 3). I don't know whether there is an eqivalent for these under Solaris nor under other platforms. Bye, Andreas. -- -------------------------------------------------------------------- Dipl.-Math. Andreas Christoph Alexanderstr. 292 26127 Oldenburg --------------------------------------------------------------------
Re: A function to get processor load
Author: Mark Nagel
Date: Thu, 08 Aug 1996 00:00
Date: Thu, 08 Aug 1996 00:00
41 lines
1847 bytes
1847 bytes
In <4udc9p$2qk@christoph.ol.sub.de> andi@christoph.ol.sub.de (Andreas Christoph) writes:
>I don't know whether there is an eqivalent for these under Solaris
>nor under other platforms.
There is a way under Solaris. Type 'man kstat' on a Solaris system
near you. More kernel statistics than you can shake a stick at.
Here's an (untested and un-error-checked) example of how to get the 5
minute load average:
#include <kstat.h>
double
get_5min_load()
{
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *ksn;
double load;
kc = kstat_open();
ksp = kstat_lookup(kc, "unix", -1, "system_misc");
kstat_read(kc, ksp, NULL);
ksn = kstat_data_lookup(ksp, "avenrun_5min");
load = (double)ksn.value.ul/256.0;
kstat_close(kc);
return load;
}
I recently wrote a simple program that dumps all of the kstat records
if anyone is interested. The only records not yet fully expanded are
the RAW and TIMER structures.
Mark
--
Mark D. Nagel <nagel@intelenet.net> InteleNet Communications
30 Executive Park, Suite 150
I did my best parenting before my child Irvine, CA 92614
was born. (paraphrased from Baby Blues) (714) 851-8250
Re: A function to get processor load
Author: Theodore C. Belding
Date: Thu, 08 Aug 1996 00:00
Date: Thu, 08 Aug 1996 00:00
20 lines
1344 bytes
1344 bytes
>>I've been working on a program that needs to get network and processor >>load information. The network part, I'll try to code it by myself. But >> I wonder if there's a Unix system call to get these informations: >>1 - Load on processor >>2 - Free physical memory >>3 - Free virtual memory >>I'm using Gnu C++ with Linux and Solaris, but I intend it to port it to >>other platforms as well. >> For CPU load, take a look at the xload sources, available at ftp://ftp.x.org The get_load.c routines work for Solaris; I don't remember about Linux. -Ted -- Ted Belding mailto:Ted.Belding@umich.edu University of Michigan Program for the Study of Complex Systems http://www-personal.engin.umich.edu/~streak/
Re: A function to get processor load
Author: Yannick JESTIN
Date: Fri, 09 Aug 1996 00:00
Date: Fri, 09 Aug 1996 00:00
44 lines
2131 bytes
2131 bytes
Mark Nagel (nagel@boris.intelenet.net) wrote:
> In <4udc9p$2qk@christoph.ol.sub.de> andi@christoph.ol.sub.de (Andreas Christoph) writes:
> >I don't know whether there is an eqivalent for these under Solaris
> >nor under other platforms.
> There is a way under Solaris. Type 'man kstat' on a Solaris system
> near you. More kernel statistics than you can shake a stick at.
The point is that there are as many different system calls as OSes. And
most of the time, you'll have to be a privileged user to perform those
operations.
There is, though, a (more) portable way, that doesn't need root
privileged: the rup(1) call, which is nothing else than a RPC call. Have
a look at the example below ( link against -lrpcsvc ).
#include <rpcsvc/rstat.h>
#include <sys/utsname.h>
void myGetLoad(double *values){
statstime stat_struct;
struct utsname uname_struct;
uname (&uname_struct);
rstat (uname_struct.nodename, &stat_struct);
values [0] = (double) stat_struct.avenrun [0] / 256.;
values [1] = (double) stat_struct.avenrun [1] / 256.;
values [2] = (double) stat_struct.avenrun [2] / 256.;
}
void main(){
double d[3];
for (;;){
sleep(3);
myGetLoad(d);
printf("load: %f %f %f\n",d[0],d[1],d[2]);
}
}
--
__+---------------------+ `o O'
\ \Yannick JESTIN \__________ooO__X__Ooo
\__\jestin@cena.dgac.fr \ \
\_____________________\___________()_()____\
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads