RinRi преди 1 година
родител
ревизия
32375728b0
променени са 10 файла, в които са добавени 82 реда и са изтрити 0 реда
  1. +4
    -0
      week08/ex1.txt
  2. Двоични данни
      week08/ex2
  3. +31
    -0
      week08/ex2.c
  4. +5
    -0
      week08/ex2.sh
  5. +5
    -0
      week08/ex3.sh
  6. Двоични данни
      week08/ex4
  7. +26
    -0
      week08/ex4.c
  8. +4
    -0
      week08/ex4.sh
  9. +3
    -0
      week08/ex5.txt
  10. +4
    -0
      week08/ex6.txt

+ 4
- 0
week08/ex1.txt Целия файл

@@ -0,0 +1,4 @@
total used free shared buff/cache available
Mem: 14Gi 2.4Gi 10Gi 88Mi 2.0Gi 11Gi
Swap: 8.0Gi 0B 8.0Gi
Total: 22Gi 2.4Gi 18Gi

Двоични данни
week08/ex2 Целия файл


+ 31
- 0
week08/ex2.c Целия файл

@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define TENMB 10*1024*1024

/* vmstat 1
* Inconsistently, probably because timings are not ideal,
* but every second free memory decreases by approximately 10MB.
* si and so are 0, because swap memory wasn't being used.
*/

/* top -d 1
* By pressing M, top sorts processes by memory usage.
* Compared to vmstat, top updates total memory usage
* slower. Every second ex2 goes to the top of the 'top'.
*/


int main() {
char *p[10];
for (int i = 0; i < 10; i++) {
p[i] = malloc(TENMB);
memset(p[i], 0, TENMB);
sleep(1);
}
for (int i = 0; i < 10; i++) {
free(p[i]);
}
}

+ 5
- 0
week08/ex2.sh Целия файл

@@ -0,0 +1,5 @@
#!/bin/sh

gcc ex2.c -o ex2
./ex2 &
vmstat 1

+ 5
- 0
week08/ex3.sh Целия файл

@@ -0,0 +1,5 @@
#!/bin/sh

gcc ex2.c -o ex2
./ex2 &
top -d 1

Двоични данни
week08/ex4 Целия файл


+ 26
- 0
week08/ex4.c Целия файл

@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/resource.h>

#define TENMB 10*1024*1024

int main() {
char *p[10];
for (int i = 0; i < 10; i++) {
p[i] = malloc(TENMB);
memset(p[i], 0, TENMB);
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) == 0) {
printf("Usage: %ldKB\n", usage.ru_maxrss);
} else {
perror("getrusage");
exit(1);
}
sleep(1);
}
for (int i = 0; i < 10; i++) {
free(p[i]);
}
}

+ 4
- 0
week08/ex4.sh Целия файл

@@ -0,0 +1,4 @@
#!/bin/sh

gcc ex4.c -o ex4
./ex4

+ 3
- 0
week08/ex5.txt Целия файл

@@ -0,0 +1,3 @@
Physical address is the actual address in the main memory, whereas virtual address is a logical one that is generated by CPU's MMU.
Virtual address points to the virtual memory, CPU and OS will take that address and convert it to the physical one to access the actual data.
All programs running on OS use virtual addresses, since they don't have access to the physical memory.

+ 4
- 0
week08/ex6.txt Целия файл

@@ -0,0 +1,4 @@
16-bit address can access 2^16 = 65536 bytes of memory
8KB is 8192 bytes.
65536 / 8192 = 8 pages
Since there are 8 pages, there are 8 table entries.

Зареждане…
Отказ
Запис