• Antelope Release 5.9 Mac OS X 10.13.2 2019-05-01

 

NAME

syscpu, sysncpu, sysloadavg, sysmem - return information about load averages, cpu usage, and memory

SYNOPSIS

#include "sysdata.h"

void syscpu(int *ncpu, CpuUsage **cpu)
int sysncpu ()
void sysloadavg(double *avg, int *nproc)
void sysmem(double *total, double *physical, double *used)

DESCRIPTION

syscpu returns the number of cpu's and a structure containing the percentage of each cpu(s) being used for user time, niced user time, system time, and idle time. sysncpu returns just the number of cpus.

typedef struct CpuUsage {
    float user ;
    float kernel ;
    float iowait ;
    float idle ;
    float swap ;
} CpuUsage ;

sysloadavg returns three load averages: a 1 minute, 5 minute and 15 minute average.

sysmem returns the size of virtual and actual physical memory in Mbytes, and the number of Mbytes in use.

EXAMPLE


double total, physical, used ;
sysmem ( &total, &physical, &used ) ;
printf ( "total    memory = %10.3f Mbytes\n", total ) ;
printf ( "physical memory = %10.3f Mbytes\n", physical ) ;
printf ( "used     memory = %10.3f Mbytes\n", used ) ;

double avg[3] ;
sysloadavg ( avg, &nproc) ;
printf ( "Load Average  (%d processes)\n", nproc ) ;
printf ( " 1 min : %5.2f\n", avg[0]) ;
printf ( " 5 min : %5.2f\n", avg[1]) ;
printf ( "15 min : %5.2f\n", avg[2]) ;

static CpuUsage     *sysusage = 0 ;
syscpu ( &ncpu, &sysusage ) ;
for ( i=0 ; i<ncpu ; i++ ) {
    printf ( "%6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%%\n",
            sysusage[i].user,
            sysusage[i].kernel,
            sysusage[i].iowait,
            sysusage[i].idle,
            sysusage[i].swap ) ;
}

LIBRARY

$(STOCKLIBS)

SEE ALSO

proc(4)

AUTHOR

Daniel Quinlan
Printer icon