Skip to content

Instantly share code, notes, and snippets.

@ethercflow
Created June 8, 2018 08:59
Show Gist options
  • Select an option

  • Save ethercflow/15431b3efd2523312eedb3a7c28744a4 to your computer and use it in GitHub Desktop.

Select an option

Save ethercflow/15431b3efd2523312eedb3a7c28744a4 to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define BLOCKSIZE 1048576
#define N 200
#define BUSYTIME 1000
int main(int argc, char *argv[]) {
int **p = malloc(N * sizeof(int*));;
int i;
while (1) {
for (i = 0; i < N; i++) {
p[i] = malloc(BLOCKSIZE);
memset(p[i],'\0',BLOCKSIZE);
usleep(BUSYTIME);
}
fprintf(stderr, "malloced\n");
for (i = 0; i < N; i++) {
free(p[i]);
usleep(BUSYTIME);
}
fprintf(stderr, "freed\n");
}
}
#!/usr/bin/env bash
i=0
while ((i<22)); do
nohup ./mem &
let ++i
echo $i
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment