Skip to content

Instantly share code, notes, and snippets.

@NaelsonDouglas
Last active June 5, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaelsonDouglas/5e2a280fe99aa82dbf1040dc649b4b1a to your computer and use it in GitHub Desktop.
Save NaelsonDouglas/5e2a280fe99aa82dbf1040dc649b4b1a to your computer and use it in GitHub Desktop.
//Créditos: http://appcrawler.com/wordpress/2013/05/13/simple-example-of-tracking-memory-using-getrusage/
#include <sys/resource.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int i = 0;
struct rusage r_usage;
while (++i <= 10) {
//Estes dois comandos apenas ficam ocupando espaço de memória
void *m = malloc(20*1024*1024);
memset(m,0,20*1024*1024);
//Faz a leitura do uso de memória no processo SELF
getrusage(RUSAGE_SELF,&r_usage);
printf("Memory usage = %ld\n",r_usage.ru_maxrss/1024); //Dividido por 1024 para ficar em kbytes
sleep (3);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment