diff --git a/mem2swap.c b/mem2swap.c new file mode 100644 --- /dev/null +++ b/mem2swap.c @@ -0,0 +1,64 @@ +/** + * $Id: mem2swap.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ + * $Author: mbroeker $ + * + * mem2swpapc usage: mem2spap [] + */ + +#include +#include +#include +#include + +#define N 1000 + +#ifndef DEFAULT_MEGS +#define DEFAULT_MEGS 64 +#endif + +int set_limit (int); + +int main (int argc, char **argv) +{ + int i, n = 0; + long int *p; + long int *p_new; + char *args[] = { "/usr/bin/free", "-m", NULL }; + int size = sizeof (*p); + int megs = DEFAULT_MEGS * 1024 * 1024; + + if (argc == 2) + megs = atoi (argv[1]) * 1024 * 1024; + + printf ("Mem2Swap - Version 1.0\n"); + + if (!set_limit (megs)) + printf ("%d MB demanded ", megs / 1024 / 1024); + else { + printf ("\tUsage: %s [MEM]\n\n", argv[0]); + printf ("Report bugs to mbroeker@largo.homelinux.org\n"); + return EXIT_FAILURE; + } + + if ((p = malloc (N * size)) == NULL) + return EXIT_SUCCESS; + + while (1) { + for (i = 0; i < N; i++) { + p[n * N + i] = size * (n * N + i); + } + if ((p_new = realloc (p, (++n + 1) * N * size))) + p = p_new; + else + break; + } + + if (p) { + printf ("and %ld MB allocated\n", p[n * N - 1] / 1024 / 1024); + free (p); + } + + printf ("\n\n"); + execve ("/usr/bin/free", args, NULL); + return EXIT_SUCCESS; +}