2011-04-19 01:30:20 +08:00
|
|
|
/*
|
|
|
|
* free.c - free(1)
|
2011-06-05 01:40:29 +08:00
|
|
|
* procps-ng utility to display free memory information
|
2011-04-19 01:30:20 +08:00
|
|
|
*
|
2012-03-02 20:29:36 +08:00
|
|
|
* Copyright (C) 1992-2012
|
|
|
|
*
|
2011-04-19 01:30:20 +08:00
|
|
|
* Mostly new, Sami Kerola <kerolasa@iki.fi> 15 Apr 2011
|
|
|
|
* All new, Robert Love <rml@tech9.net> 18 Nov 2002
|
|
|
|
* Original by Brian Edmonds and Rafal Maszkowski 14 Dec 1992
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Love
|
|
|
|
* Copyright 2004 Albert Cahalan
|
2012-03-02 20:29:36 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-04-19 01:30:20 +08:00
|
|
|
*/
|
2011-11-03 18:37:10 +08:00
|
|
|
|
2012-01-04 06:53:51 +08:00
|
|
|
#include "config.h"
|
2011-10-09 04:24:06 +08:00
|
|
|
#include "c.h"
|
|
|
|
#include "nls.h"
|
2012-01-04 06:53:51 +08:00
|
|
|
#include "strutils.h"
|
2012-03-23 20:32:24 +08:00
|
|
|
#include "fileutils.h"
|
2011-10-09 04:24:06 +08:00
|
|
|
|
2011-11-03 18:37:10 +08:00
|
|
|
#include <locale.h>
|
2011-04-19 01:30:20 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <ctype.h>
|
2004-01-30 12:47:14 +08:00
|
|
|
#include <getopt.h>
|
2002-02-02 06:47:29 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-04-16 15:03:57 +08:00
|
|
|
#include <proc/procps.h>
|
2015-06-23 20:22:50 +08:00
|
|
|
|
2011-04-19 01:30:20 +08:00
|
|
|
#ifndef SIZE_MAX
|
|
|
|
#define SIZE_MAX 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define FREE_HUMANREADABLE (1 << 1)
|
|
|
|
#define FREE_LOHI (1 << 2)
|
2014-07-30 03:31:46 +08:00
|
|
|
#define FREE_WIDE (1 << 3)
|
2011-04-19 01:30:20 +08:00
|
|
|
#define FREE_TOTAL (1 << 4)
|
|
|
|
#define FREE_SI (1 << 5)
|
|
|
|
#define FREE_REPEAT (1 << 6)
|
|
|
|
#define FREE_REPEATCOUNT (1 << 7)
|
|
|
|
|
|
|
|
struct commandline_arguments {
|
|
|
|
int exponent; /* demanded in kilos, magas... */
|
|
|
|
float repeat_interval; /* delay in seconds */
|
|
|
|
int repeat_counter; /* number of repeats */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* function prototypes */
|
|
|
|
static void usage(FILE * out);
|
|
|
|
double power(unsigned int base, unsigned int expo);
|
|
|
|
static const char *scale_size(unsigned long size, int flags, struct commandline_arguments args);
|
|
|
|
|
|
|
|
static void __attribute__ ((__noreturn__))
|
|
|
|
usage(FILE * out)
|
|
|
|
{
|
2011-10-09 04:24:06 +08:00
|
|
|
fputs(USAGE_HEADER, out);
|
2011-04-19 01:30:20 +08:00
|
|
|
fprintf(out,
|
2011-10-09 04:24:06 +08:00
|
|
|
_(" %s [options]\n"), program_invocation_short_name);
|
|
|
|
fputs(USAGE_OPTIONS, out);
|
2013-10-10 06:56:44 +08:00
|
|
|
fputs(_(" -b, --bytes show output in bytes\n"), out);
|
2015-04-03 16:18:58 +08:00
|
|
|
fputs(_(" --kilo show output in kilobytes\n"), out);
|
|
|
|
fputs(_(" --mega show output in megabytes\n"), out);
|
|
|
|
fputs(_(" --giga show output in gigabytes\n"), out);
|
2013-10-10 06:56:44 +08:00
|
|
|
fputs(_(" --tera show output in terabytes\n"), out);
|
2015-04-03 16:18:58 +08:00
|
|
|
fputs(_(" --peta show output in petabytes\n"), out);
|
|
|
|
fputs(_(" -k, --kibi show output in kibibytes\n"), out);
|
|
|
|
fputs(_(" -m, --mebi show output in mebibytes\n"), out);
|
|
|
|
fputs(_(" -g, --gibi show output in gibibytes\n"), out);
|
|
|
|
fputs(_(" --tebi show output in tebibytes\n"), out);
|
|
|
|
fputs(_(" --pebi show output in pebibytes\n"), out);
|
2013-10-10 06:56:44 +08:00
|
|
|
fputs(_(" -h, --human show human-readable output\n"), out);
|
|
|
|
fputs(_(" --si use powers of 1000 not 1024\n"), out);
|
|
|
|
fputs(_(" -l, --lohi show detailed low and high memory statistics\n"), out);
|
|
|
|
fputs(_(" -t, --total show total for RAM + swap\n"), out);
|
|
|
|
fputs(_(" -s N, --seconds N repeat printing every N seconds\n"), out);
|
|
|
|
fputs(_(" -c N, --count N repeat printing N times, then exit\n"), out);
|
2014-07-30 03:23:19 +08:00
|
|
|
fputs(_(" -w, --wide wide output\n"), out);
|
2011-10-09 04:24:06 +08:00
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2013-10-10 06:56:44 +08:00
|
|
|
fputs(_(" --help display this help and exit\n"), out);
|
2011-10-09 04:24:06 +08:00
|
|
|
fputs(USAGE_VERSION, out);
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("free(1)"));
|
2011-04-19 01:30:20 +08:00
|
|
|
|
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
double power(unsigned int base, unsigned int expo)
|
|
|
|
{
|
|
|
|
return (expo == 0) ? 1 : base * power(base, expo - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* idea of this function is copied from top size scaling */
|
|
|
|
static const char *scale_size(unsigned long size, int flags, struct commandline_arguments args)
|
|
|
|
{
|
2015-04-03 16:18:58 +08:00
|
|
|
static char nextup[] = { 'B', 'K', 'M', 'G', 'T', 'P', 0 };
|
2011-10-09 04:24:06 +08:00
|
|
|
static char buf[BUFSIZ];
|
2011-04-19 01:30:20 +08:00
|
|
|
int i;
|
|
|
|
char *up;
|
|
|
|
float base;
|
|
|
|
|
|
|
|
if (flags & FREE_SI)
|
|
|
|
base = 1000.0;
|
|
|
|
else
|
|
|
|
base = 1024.0;
|
|
|
|
|
|
|
|
/* default output */
|
|
|
|
if (args.exponent == 0 && !(flags & FREE_HUMANREADABLE)) {
|
|
|
|
snprintf(buf, sizeof(buf), "%ld", size);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & FREE_HUMANREADABLE)) {
|
|
|
|
if (args.exponent == 1) {
|
|
|
|
/* in bytes, which can not be in SI */
|
2012-06-26 21:06:45 +08:00
|
|
|
snprintf(buf, sizeof(buf), "%lld", ((long long int)size) * 1024);
|
2011-04-19 01:30:20 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
if (args.exponent == 2) {
|
|
|
|
if (!(flags & FREE_SI))
|
|
|
|
snprintf(buf, sizeof(buf), "%ld", size);
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%ld", (long int)(size / 0.9765625));
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
if (args.exponent > 2) {
|
|
|
|
/* In desired scale. */
|
|
|
|
snprintf(buf, sizeof(buf), "%ld",
|
|
|
|
(long int)(size / power(base, args.exponent - 2))
|
|
|
|
);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* human readable output */
|
|
|
|
up = nextup;
|
2015-10-24 10:17:36 +08:00
|
|
|
for (i = 1; up[0] != 0; i++, up++) {
|
2011-04-19 01:30:20 +08:00
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
if (4 >= snprintf(buf, sizeof(buf), "%ld%c", (long)size * 1024, *up))
|
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if (!(flags & FREE_SI)) {
|
|
|
|
if (4 >= snprintf(buf, sizeof(buf), "%ld%c", size, *up))
|
|
|
|
return buf;
|
|
|
|
} else {
|
|
|
|
if (4 >=
|
|
|
|
snprintf(buf, sizeof(buf), "%ld%c",
|
|
|
|
(long)(size / 0.9765625), *up))
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2015-04-03 16:18:58 +08:00
|
|
|
case 6:
|
2011-04-19 01:30:20 +08:00
|
|
|
if (4 >=
|
|
|
|
snprintf(buf, sizeof(buf), "%.1f%c",
|
|
|
|
(float)(size / power(base, i - 2)), *up))
|
|
|
|
return buf;
|
|
|
|
if (4 >=
|
|
|
|
snprintf(buf, sizeof(buf), "%ld%c",
|
|
|
|
(long)(size / power(base, i - 2)), *up))
|
|
|
|
return buf;
|
|
|
|
break;
|
2015-04-03 16:18:58 +08:00
|
|
|
case 7:
|
2011-04-19 01:30:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-02-02 06:47:29 +08:00
|
|
|
}
|
2011-04-19 01:30:20 +08:00
|
|
|
/*
|
2015-04-03 16:18:58 +08:00
|
|
|
* On system where there is more than exbibyte of memory or swap the
|
2011-04-19 01:30:20 +08:00
|
|
|
* output does not fit to column. For incoming few years this should
|
2015-04-03 16:18:58 +08:00
|
|
|
* not be a big problem (wrote at Apr, 2015).
|
2011-04-19 01:30:20 +08:00
|
|
|
*/
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-04-03 16:18:58 +08:00
|
|
|
static void check_unit_set(int *unit_set)
|
|
|
|
{
|
|
|
|
if (*unit_set)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Multiple unit options doesn't make sense."));
|
|
|
|
*unit_set = 1;
|
|
|
|
}
|
|
|
|
|
2011-04-19 01:30:20 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2015-04-03 16:18:58 +08:00
|
|
|
int c, flags = 0, unit_set = 0;
|
2011-04-19 01:30:20 +08:00
|
|
|
char *endptr;
|
|
|
|
struct commandline_arguments args;
|
2016-05-12 01:00:00 +08:00
|
|
|
struct procps_meminfo *mem_info = NULL;
|
2011-04-19 01:30:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For long options that have no equivalent short option, use a
|
|
|
|
* non-character as a pseudo short option, starting with CHAR_MAX + 1.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
SI_OPTION = CHAR_MAX + 1,
|
2015-04-03 16:18:58 +08:00
|
|
|
KILO_OPTION,
|
|
|
|
MEGA_OPTION,
|
|
|
|
GIGA_OPTION,
|
2011-04-19 01:30:20 +08:00
|
|
|
TERA_OPTION,
|
2015-04-03 16:18:58 +08:00
|
|
|
PETA_OPTION,
|
|
|
|
TEBI_OPTION,
|
|
|
|
PEBI_OPTION,
|
2011-04-19 01:30:20 +08:00
|
|
|
HELP_OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
{ "bytes", no_argument, NULL, 'b' },
|
2015-04-03 16:18:58 +08:00
|
|
|
{ "kilo", no_argument, NULL, KILO_OPTION },
|
|
|
|
{ "mega", no_argument, NULL, MEGA_OPTION },
|
|
|
|
{ "giga", no_argument, NULL, GIGA_OPTION },
|
2011-04-19 01:30:20 +08:00
|
|
|
{ "tera", no_argument, NULL, TERA_OPTION },
|
2015-04-03 16:18:58 +08:00
|
|
|
{ "peta", no_argument, NULL, PETA_OPTION },
|
|
|
|
{ "kibi", no_argument, NULL, 'k' },
|
|
|
|
{ "mebi", no_argument, NULL, 'm' },
|
|
|
|
{ "gibi", no_argument, NULL, 'g' },
|
|
|
|
{ "tebi", no_argument, NULL, TEBI_OPTION },
|
|
|
|
{ "pebi", no_argument, NULL, PEBI_OPTION },
|
2011-04-19 01:30:20 +08:00
|
|
|
{ "human", no_argument, NULL, 'h' },
|
|
|
|
{ "si", no_argument, NULL, SI_OPTION },
|
|
|
|
{ "lohi", no_argument, NULL, 'l' },
|
|
|
|
{ "total", no_argument, NULL, 't' },
|
|
|
|
{ "seconds", required_argument, NULL, 's' },
|
|
|
|
{ "count", required_argument, NULL, 'c' },
|
2014-07-30 03:23:19 +08:00
|
|
|
{ "wide", no_argument, NULL, 'w' },
|
2011-04-19 01:30:20 +08:00
|
|
|
{ "help", no_argument, NULL, HELP_OPTION },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2014-07-30 03:31:46 +08:00
|
|
|
/* defaults */
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 0;
|
|
|
|
args.repeat_interval = 1000000;
|
2011-09-24 14:41:26 +08:00
|
|
|
args.repeat_counter = 0;
|
2011-04-19 01:30:20 +08:00
|
|
|
|
2013-02-21 01:31:48 +08:00
|
|
|
#ifdef HAVE_PROGRAM_INVOCATION_NAME
|
|
|
|
program_invocation_name = program_invocation_short_name;
|
|
|
|
#endif
|
2011-11-03 18:37:10 +08:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
2012-03-23 20:32:24 +08:00
|
|
|
atexit(close_stdout);
|
2011-11-03 18:37:10 +08:00
|
|
|
|
2014-07-30 03:31:46 +08:00
|
|
|
while ((c = getopt_long(argc, argv, "bkmghltc:ws:V", longopts, NULL)) != -1)
|
2011-04-19 01:30:20 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
2015-04-03 16:18:58 +08:00
|
|
|
check_unit_set(&unit_set);
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 1;
|
|
|
|
break;
|
|
|
|
case 'k':
|
2015-04-03 16:18:58 +08:00
|
|
|
check_unit_set(&unit_set);
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 2;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2015-04-03 16:18:58 +08:00
|
|
|
check_unit_set(&unit_set);
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 3;
|
|
|
|
break;
|
|
|
|
case 'g':
|
2015-04-03 16:18:58 +08:00
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 4;
|
|
|
|
break;
|
|
|
|
case TEBI_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 5;
|
|
|
|
break;
|
|
|
|
case PEBI_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 6;
|
|
|
|
break;
|
|
|
|
case KILO_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 2;
|
|
|
|
flags |= FREE_SI;
|
|
|
|
break;
|
|
|
|
case MEGA_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 3;
|
|
|
|
flags |= FREE_SI;
|
|
|
|
break;
|
|
|
|
case GIGA_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 4;
|
2015-04-03 16:18:58 +08:00
|
|
|
flags |= FREE_SI;
|
2011-04-19 01:30:20 +08:00
|
|
|
break;
|
|
|
|
case TERA_OPTION:
|
2015-04-03 16:18:58 +08:00
|
|
|
check_unit_set(&unit_set);
|
2011-04-19 01:30:20 +08:00
|
|
|
args.exponent = 5;
|
2015-04-03 16:18:58 +08:00
|
|
|
flags |= FREE_SI;
|
|
|
|
break;
|
|
|
|
case PETA_OPTION:
|
|
|
|
check_unit_set(&unit_set);
|
|
|
|
args.exponent = 6;
|
|
|
|
flags |= FREE_SI;
|
2011-04-19 01:30:20 +08:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
flags |= FREE_HUMANREADABLE;
|
|
|
|
break;
|
|
|
|
case SI_OPTION:
|
|
|
|
flags |= FREE_SI;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
flags |= FREE_LOHI;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
flags |= FREE_TOTAL;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
flags |= FREE_REPEAT;
|
2015-08-08 19:04:01 +08:00
|
|
|
errno = 0;
|
2011-04-19 01:30:20 +08:00
|
|
|
args.repeat_interval = (1000000 * strtof(optarg, &endptr));
|
|
|
|
if (errno || optarg == endptr || (endptr && *endptr))
|
2012-01-03 15:48:43 +08:00
|
|
|
xerrx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);
|
2011-04-19 01:30:20 +08:00
|
|
|
if (args.repeat_interval < 1)
|
2012-01-03 15:48:43 +08:00
|
|
|
xerrx(EXIT_FAILURE,
|
2011-10-09 04:24:06 +08:00
|
|
|
_("seconds argument `%s' is not positive number"), optarg);
|
2011-04-19 01:30:20 +08:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
flags |= FREE_REPEAT;
|
|
|
|
flags |= FREE_REPEATCOUNT;
|
2012-01-04 06:53:51 +08:00
|
|
|
args.repeat_counter = strtol_or_err(optarg,
|
|
|
|
_("failed to parse count argument"));
|
2012-02-26 19:26:59 +08:00
|
|
|
if (args.repeat_counter < 1)
|
2012-01-04 06:53:51 +08:00
|
|
|
error(EXIT_FAILURE, ERANGE,
|
|
|
|
_("failed to parse count argument: '%s'"), optarg);
|
2011-04-19 01:30:20 +08:00
|
|
|
break;
|
2014-07-30 03:23:19 +08:00
|
|
|
case 'w':
|
|
|
|
flags |= FREE_WIDE;
|
2014-07-12 04:34:06 +08:00
|
|
|
break;
|
2011-04-19 01:30:20 +08:00
|
|
|
case HELP_OPTION:
|
|
|
|
usage(stdout);
|
|
|
|
case 'V':
|
2011-10-09 04:24:06 +08:00
|
|
|
printf(PROCPS_NG_VERSION);
|
2011-04-19 01:30:20 +08:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
default:
|
|
|
|
usage(stderr);
|
|
|
|
}
|
|
|
|
|
2015-06-23 20:22:50 +08:00
|
|
|
if (procps_meminfo_new(&mem_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create meminfo structure"));
|
2011-04-19 01:30:20 +08:00
|
|
|
do {
|
2011-12-18 01:32:47 +08:00
|
|
|
/* Translation Hint: You can use 9 character words in
|
|
|
|
* the header, and the words need to be right align to
|
|
|
|
* beginning of a number. */
|
2014-07-30 03:23:19 +08:00
|
|
|
if (flags & FREE_WIDE) {
|
2014-08-20 19:21:22 +08:00
|
|
|
printf(_(" total used free shared buffers cache available"));
|
2014-07-30 03:23:19 +08:00
|
|
|
} else {
|
2014-08-20 19:21:22 +08:00
|
|
|
printf(_(" total used free shared buff/cache available"));
|
2014-07-30 03:23:19 +08:00
|
|
|
}
|
2014-07-12 04:34:06 +08:00
|
|
|
printf("\n");
|
2011-10-09 04:24:06 +08:00
|
|
|
printf("%-7s", _("Mem:"));
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_TOTAL), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_USED), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_FREE), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_SHARED), flags, args));
|
2014-07-30 03:23:19 +08:00
|
|
|
if (flags & FREE_WIDE) {
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_BUFFERS),
|
2015-06-23 20:22:50 +08:00
|
|
|
flags, args));
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_CACHED)
|
2015-06-23 20:22:50 +08:00
|
|
|
, flags, args));
|
2014-07-30 03:23:19 +08:00
|
|
|
} else {
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_BUFFERS)+
|
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_CACHED), flags, args));
|
2014-07-30 03:23:19 +08:00
|
|
|
}
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_AVAILABLE), flags, args));
|
2011-04-19 01:30:20 +08:00
|
|
|
printf("\n");
|
|
|
|
/*
|
|
|
|
* Print low vs. high information, if the user requested it.
|
|
|
|
* Note we check if low_total == 0: if so, then this kernel
|
|
|
|
* does not export the low and high stats. Note we still want
|
|
|
|
* to print the high info, even if it is zero.
|
|
|
|
*/
|
|
|
|
if (flags & FREE_LOHI) {
|
2011-10-09 04:24:06 +08:00
|
|
|
printf("%-7s", _("Low:"));
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMLO_TOTAL), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMLO_USED), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMLO_FREE), flags, args));
|
2011-04-19 01:30:20 +08:00
|
|
|
printf("\n");
|
|
|
|
|
2011-10-09 04:24:06 +08:00
|
|
|
printf("%-7s", _("High:"));
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMHI_TOTAL), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMHI_USED), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEMHI_FREE), flags, args));
|
2011-04-19 01:30:20 +08:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2011-10-09 04:24:06 +08:00
|
|
|
printf("%-7s", _("Swap:"));
|
2016-05-12 01:00:00 +08:00
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_TOTAL), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_USED), flags, args));
|
|
|
|
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_FREE), flags, args));
|
2011-04-19 01:30:20 +08:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (flags & FREE_TOTAL) {
|
2011-10-09 04:24:06 +08:00
|
|
|
printf("%-7s", _("Total:"));
|
2015-06-23 20:22:50 +08:00
|
|
|
printf(" %11s", scale_size(
|
2016-05-12 01:00:00 +08:00
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_TOTAL)+
|
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_TOTAL), flags, args));
|
2015-06-23 20:22:50 +08:00
|
|
|
printf(" %11s", scale_size(
|
2016-05-12 01:00:00 +08:00
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_USED)+
|
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_USED), flags, args));
|
2015-06-23 20:22:50 +08:00
|
|
|
printf(" %11s", scale_size(
|
2016-05-12 01:00:00 +08:00
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_MEM_FREE)+
|
|
|
|
procps_meminfo_get(mem_info, PROCPS_MEMINFO_SWAP_FREE), flags, args));
|
2011-04-19 01:30:20 +08:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
if (flags & FREE_REPEATCOUNT) {
|
|
|
|
args.repeat_counter--;
|
|
|
|
if (args.repeat_counter < 1)
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
if (flags & FREE_REPEAT) {
|
|
|
|
printf("\n");
|
|
|
|
usleep(args.repeat_interval);
|
|
|
|
}
|
|
|
|
} while ((flags & FREE_REPEAT));
|
2002-02-02 06:47:29 +08:00
|
|
|
|
2011-04-19 01:30:20 +08:00
|
|
|
exit(EXIT_SUCCESS);
|
2002-02-02 06:47:29 +08:00
|
|
|
}
|