Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/resource.h>
- typedef struct {
- unsigned long size, resident, share, text, lib, data, dt;
- }St;
- void readMemoryStatus()
- {
- St r;
- FILE* file = fopen("/proc/self/statm", "r");
- if(file){
- int rv = fscanf(file,"%lu %lu %lu %lu %lu %lu %lu", &r.size, &r.resident, &r.share, &r.text, &r.lib, &r.data, &r.dt);
- if(rv == 7){
- printf("%lu %lu %lu %lu %lu %lu %lu\n", r.size, r.resident, r.share, r.text, r.lib, r.data, r.dt);
- }
- fclose(file);
- }
- }
- long int g_Variable = 0;
- long int testas(long int i) {
- if(i <= 0) return 0;
- g_Variable++;
- readMemoryStatus();
- return testas(i - 1);
- }
- //long int -2147483648 2147483647
- int main() {
- long int i = 5;
- printf("\n%ld %ld\n", testas(i), g_Variable);
- printf("%ld\n", g_Variable);
- return 0;
- }
- /*
- with -O0 and i = 500000;
- in pages
- ...
- 3140 2403 353 1 0 2090 0
- ...
- 3141 2403 353 1 0 2091 0
- ...
- 3142 2403 353 1 0 2092 0
- SEGFAULT (core dumped)
- valgrind --tool=massif ./testas
- Stack overflow in thread #1: can't grow stack to 0x1ffe801000
- Process terminating with default action of signal 11 (SIGSEGV)
- ulimit
- stack size (kbytes, -s) 8192
- ok with -03 and i = 500000:
- 1127 193 177 1 0 77 0
- */
Add Comment
Please, Sign In to add comment