You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
707 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #define TENMB 10*1024*1024
  6. /* vmstat 1
  7. * Inconsistently, probably because timings are not ideal,
  8. * but every second free memory decreases by approximately 10MB.
  9. * si and so are 0, because swap memory wasn't being used.
  10. */
  11. /* top -d 1
  12. * By pressing M, top sorts processes by memory usage.
  13. * Compared to vmstat, top updates total memory usage
  14. * slower. Every second ex2 goes to the top of the 'top'.
  15. */
  16. int main() {
  17. char *p[10];
  18. for (int i = 0; i < 10; i++) {
  19. p[i] = malloc(TENMB);
  20. memset(p[i], 0, TENMB);
  21. sleep(1);
  22. }
  23. for (int i = 0; i < 10; i++) {
  24. free(p[i]);
  25. }
  26. }