Question: #include #include #include char *gmsg = Global Message; const int buffer_size = 100; int main(int argc, char *argv[], char *envp[]) { char *lmsg = Local

#include#include #include 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 report "); printf("argv: %lx ", (unsigned long) argv); printf("argv[0]: %lx ", (unsigned long) argv[0]); printf("envp: %lx ", (unsigned long) envp); printf("envp[0]: %lx ", (unsigned long) envp[0]); printf("lmsg: %lx ", (unsigned long) lmsg); printf("&lmsg: %lx ", (unsigned long) &lmsg); printf("gmsg: %lx ", (unsigned long) gmsg); printf("&gmsg: %lx ", (unsigned long) &gmsg); printf("main: %lx ", (unsigned long) &main); printf("sbrk(0): %lx ", (unsigned long) sbrk(0)); printf("&buf: %lx ", (unsigned long) &buf); for (i = 0; i
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? 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
