Menu

(Solved) : Include Include Include Char Gmsg Global Message Const Int Buffersize 100 Int Main Int Arg Q44040897 . . .

Examining the runtime memory map Compile and run 3000memview.com, then consider the following questions. 1. Why are the addre

#include <stdio.h>#include <stdlib.h>#include <unistd.h>char *gmsg = “Global Message”;const int buffer_size = 100;int main(int argc, char *argv[], char *envp[]){ char *lmsg = “Local Message”; char *buf[buffer_size]; int i; printf(“Memory reportn”); printf(“argv: %lxn”, (unsigned long) argv); printf(“argv[0]: %lxn”, (unsigned long) argv[0]); printf(“envp: %lxn”, (unsigned long) envp); printf(“envp[0]: %lxn”, (unsigned long) envp[0]); printf(“lmsg: %lxn”, (unsigned long) lmsg); printf(“&lmsg: %lxn”, (unsigned long) &lmsg); printf(“gmsg: %lxn”, (unsigned long) gmsg); printf(“&gmsg: %lxn”, (unsigned long) &gmsg); printf(“main: %lxn”, (unsigned long) &main); printf(“sbrk(0): %lxn”, (unsigned long) sbrk(0)); printf(“&buf: %lxn”, (unsigned long) &buf); for (i = 0; i<buffer_size; i++) { buf[i] = (char *) malloc(4096); } printf(“buf[0]: %lxn”, (unsigned long) buf[0]); printf(“sbrk(0): %lxn”, (unsigned long) sbrk(0)); return 0;}

OS is Ubuntu 18.04

Examining the runtime memory map Compile and run 3000memview.com, then consider the following questions. 1. Why are the addresses inconsistent between runs? 2. Roughly where does the stack seem to be? The heap? Code? Global variables? 3. Observe how the heap grows (i.e. the value of sbrk changes) in response to malloc calls. Would you expect the heap to ever run into the stack? Why or why not? 4. Change each malloc call to allocate more than 128K. What happens to the values of sbrk? Why? (Hint: use strace) 5. Add more code and data to the program, and add more printf’s to see where things are. Are things where you expect them to be? Show transcribed image text Examining the runtime memory map Compile and run 3000memview.com, then consider the following questions. 1. Why are the addresses inconsistent between runs? 2. Roughly where does the stack seem to be? The heap? Code? Global variables? 3. Observe how the heap grows (i.e. the value of sbrk changes) in response to malloc calls. Would you expect the heap to ever run into the stack? Why or why not? 4. Change each malloc call to allocate more than 128K. What happens to the values of sbrk? Why? (Hint: use strace) 5. Add more code and data to the program, and add more printf’s to see where things are. Are things where you expect them to be?

Expert Answer


Answer to #include #include #include char *gmsg = “Global Message”; const int buffer_size = 100; int main(int argc, char *argv[], …

OR