/* * 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: memory-pressure.c,v 1.2 2012/01/25 19:39:01 james.stevenson Exp $ * * Author: * NAME: James Stevenson * WWW: http://www.stev.org * */ #include #include #include #include #include #include int verbose = 0; void print_help(FILE *fp, char *app) { fprintf(fp, "Usage: %s \n", app); fprintf(fp, "\n"); fprintf(fp, "\t-s Delay between touching memory\n"); fprintf(fp, "\t-v Be more verbose\n"); fprintf(fp, "\n"); } int main(int argc, char **argv) { int size = 0; char *buffer = 0; int c = 0; int delay = 1; while( (c = getopt(argc, argv, "s:v")) != -1) { switch(c) { case 's': delay = atoi(optarg); break; case 'v': verbose++; break; default: break; } } if (argc - optind < 1) { print_help(stdout, argv[0]); exit(EXIT_FAILURE); } size = atoi(argv[argc - 1]); buffer = malloc(size * 1024); if (!buffer) { perror("malloc"); exit(EXIT_FAILURE); } while(1) { printf("Touching Memory\n"); memset(buffer, 0, size * 1024); sleep(delay); } return 0; }