Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ex2.c 707 B

1 år sedan
12345678910111213141516171819202122232425262728293031
  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. }