Question: You are given a piece of code below. #include #include #include int main() { char buffer [100]; int fd, num; printf(address of buffer: %x ,

You are given a piece of code below.

#include #include #include

int main()

{

char buffer [100]; int fd, num;

printf(address of buffer: %x , buffer);

fd = open(/home/readme, O_RDONLY);

num = read(fd, buffer, 100*sizeof(int));

if (num <= 0) {

printf(read data from readme failed );

} else {

printf(data from readme: %s , buffer);

}

close(fd);

}

1. When you (root user) login to computer and run this program, will the program itself run in user mode or kernel mode?

2. The statement of printf(address of buffer: %x , buffer) will print a virtual address or physical address?

3. When accessing the variables buffer, fd and num, if their virtual addresses are 0xbfdc4084, 0xbfdc4020, 0xbfdc401c, how many times does the OS kernel need to refer to page tables to do virtual-to-physical address translation? Why? (hint: we assume the size of one page is 4KB, and there is no context switch when the process accessing the three variables.)

4. When does OS allocate physical memory for variable buffer?

5. What does OS kernel need to do when the program close(fd)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!