63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <stdlib.h>
#include <stdio.h>
#ifndef NO_GETOPT
#include <getopt.h>
#endif
#define BARLEN 35
#define HEADERLEN 14
#define VERSION "0.8.6"
extern char *optarg;
extern int optind, opterr, optopt;
void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN],int usefull) {
char percentone[BARLEN], percenttwo[BARLEN], remain[BARLEN];
|
|
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <stdlib.h>
#include <stdio.h>
#ifndef NO_GETOPT
#include <getopt.h>
#endif
#define BARLEN 35
#define HEADERLEN 14
#define VERSION "0.8.7"
extern char *optarg;
extern int optind, opterr, optopt;
void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN],int usefull) {
char percentone[BARLEN], percenttwo[BARLEN], remain[BARLEN];
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
int i, divisor=1024, dototals=0, doold=0, linestoup=2;
unsigned long meminfo_cached;
#ifndef HAVE_LIBSTATGRAB
struct sysinfo sinfo;
meminfo_cached=get_meminfo("Cached:");
#else
mem_stat_t *mem_stats=NULL;
swap_stat_t *swap_stats=NULL;
struct systeminfo_st {
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
} sinfo;
statgrab_init();
#ifdef HAVE_STATGRAB_DROP_PRIVILEGES
/* Drop setuid/setgid privileges. */
if (statgrab_drop_privileges() != 0) {
perror("Error. Failed to drop privileges");
return 1;
}
#endif
#endif
#ifdef NO_GETOPT
|
|
|
|
|
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
int i, divisor=1024, dototals=0, doold=0, linestoup=2;
unsigned long meminfo_cached;
#ifndef HAVE_LIBSTATGRAB
struct sysinfo sinfo;
meminfo_cached=get_meminfo("Cached:");
#else
sg_mem_stats *mem_stats=NULL;
sg_swap_stats *swap_stats=NULL;
struct systeminfo_st {
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
} sinfo;
sg_init();
#ifdef HAVE_STATGRAB_DROP_PRIVILEGES
/* Drop setuid/setgid privileges. */
if (sg_drop_privileges() != 0) {
perror("Error. Failed to drop privileges");
return 1;
}
#endif
#endif
#ifdef NO_GETOPT
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
}
}
#endif
while(1) {
#ifndef HAVE_LIBSTATGRAB
sysinfo(&sinfo);
#else
if(((mem_stats=get_memory_stats()) == NULL) || (swap_stats=get_swap_stats()) == NULL) {
printf("Couldn't get memory information, exiting.\n");
return(-1);
}
meminfo_cached=mem_stats->cache;
sinfo.totalram=mem_stats->total;
sinfo.freeram=mem_stats->free;
sinfo.sharedram=0;
|
|
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
}
}
#endif
while(1) {
#ifndef HAVE_LIBSTATGRAB
sysinfo(&sinfo);
#else
if(((mem_stats=sg_get_mem_stats()) == NULL) || (swap_stats=sg_get_swap_stats()) == NULL) {
printf("Couldn't get memory information, exiting.\n");
return(-1);
}
meminfo_cached=mem_stats->cache;
sinfo.totalram=mem_stats->total;
sinfo.freeram=mem_stats->free;
sinfo.sharedram=0;
|