Skip to content

Commit

Permalink
mem.c with vps support
Browse files Browse the repository at this point in the history
  • Loading branch information
hugulas committed Jul 22, 2019
1 parent 3b8631a commit ed27ee7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions linux-perf/sample2/mem.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main()
int main(int argc, char *argv[])
{
int n = atoi(argv[1]);
int enough = 1;
while(1)
{

// use 1MB memory
void *m = malloc(1024*1024);
memset(m,0,1024*1024);
// sleep 1 second
sleep(1000);
if (enough) {
void *m = malloc(1024*1024);
if (!m) {
enough = 0;
printf("No more memory to use");
}
else {
memset(m,0,1024*1024);
}
}
// sleep n micro seconds
usleep(n);
}
return 0;
}

0 comments on commit ed27ee7

Please sign in to comment.