Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions