Last active
June 5, 2019 16:26
-
-
Save NaelsonDouglas/5e2a280fe99aa82dbf1040dc649b4b1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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