wmclockmon: update change-log
[dockapps.git] / wmmemload / src / mem_solaris.c
blob1e11306ccd3be29722c634faa9a2725dbfac1c99
1 /*
2 * mem_solaric.c - module to get memory/swap usages in percent, for Solaris
4 * Copyright (c) 2001 Jonathan Lang <lang@synopsys.com>
5 * Copyright (c) 2002 Seiichi SATO <ssato@sh.rim.or.jp>
7 * licensed under the GPL
8 */
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include "mem.h"
19 #include <sys/stat.h>
20 #include <sys/swap.h>
22 /* initialize function */
23 void mem_init(void)
25 /* solaris doesn't need initialization */
26 return;
29 /* return memory/swap usage in percent 0 to 100 */
30 void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
32 static int mem_total;
33 static int mem_free;
34 static int swap_total;
35 static int swap_free;
36 struct anoninfo anon;
38 /* get mem usage */
39 mem_total = sysconf(_SC_PHYS_PAGES);
40 mem_free = sysconf(_SC_AVPHYS_PAGES);
42 /* get swap usage */
43 if (swapctl(SC_AINFO, &anon) == -1)
44 exit(1);
45 swap_total = anon.ani_max;
46 swap_free = anon.ani_max - anon.ani_resv;
48 /* calc mem/swap usage in percent */
49 *per_mem = 100 * (1 - ((double) mem_free / (double) mem_total));
50 *per_swap = 100 * (1 - ((double) swap_free / (double) swap_total));