--- projects/libstatgrab/examples/vm_stats.c 2004/01/16 15:54:52 1.6 +++ projects/libstatgrab/examples/vm_stats.c 2004/04/05 16:23:08 1.9 @@ -16,6 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id: vm_stats.c,v 1.9 2004/04/05 16:23:08 tdb Exp $ */ #include @@ -25,34 +27,21 @@ int main(int argc, char **argv){ - extern char *optarg; - extern int optind; - int c; + sg_mem_stats *mem_stats; + sg_swap_stats *swap_stats; - int delay = 1; - mem_stat_t *mem_stats; - swap_stat_t *swap_stats; - long long total, free; - while ((c = getopt(argc, argv, "d:")) != -1){ - switch (c){ - case 'd': - delay = atoi(optarg); - break; - } - } - /* Initialise statgrab */ - statgrab_init(); + sg_init(); /* Drop setuid/setgid privileges. */ - if (statgrab_drop_privileges() != 0) { + if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); return 1; } - if( ((mem_stats=get_memory_stats()) != NULL) && (swap_stats=get_swap_stats()) != NULL){ + if( ((mem_stats=sg_get_mem_stats()) != NULL) && (swap_stats=sg_get_swap_stats()) != NULL){ printf("Total memory in bytes : %lld\n", mem_stats->total); printf("Used memory in bytes : %lld\n", mem_stats->used); printf("Cache memory in bytes : %lld\n", mem_stats->cache); @@ -67,6 +56,10 @@ int main(int argc, char **argv){ printf("Total VM usage : %5.2f%%\n", 100 - (((float)total/(float)free))); + } + else { + printf("Unable to get VM stats.\n"); + exit(1); } exit(0); }