What does the OS kernel and CPU do when Process A needs to read a word from the

What does the os kernel and cpu do when process a

This preview shows page 4 - 7 out of 15 pages.

2.What does the OS kernel (and CPU) do when Process A needs to read a word from the disk? ( Back to Beginning ) The ultimate aim of this question is to find out how your Unix system layouts different parts of your process in the virtual memory. The question consists of three parts. The first part is to complete a program that prints out the memory addresses of various components of the process (eg, global variables, local variables, dynamically allocated variables, functions, command line arguments, and environment variables). This program is then used in the second part to recreate a snapshot of the memory layout of the process. Finally in the third, you will answer a number of questions related to the memory management based on your observation and analysis. 1. (5 marks) Complete the following C program, memory.c , so that it displays the addresses of a. functions f1 , f2 , and main ; b. all string literals such as "Hello, world!";
Image of page 4
c. all initialized global variables; d. all un-initialized global variables; e. all dynamically allocated memories; f. all formal parameters in functions; g. all local variables; h. start and end of its command line arguments; i. start and end of its environment (variables and values). Note: the function addr in the code below only handles 32- bit virtual addresses. If your operating system is 64 bits, the function will not work. You can either modify the function so that it can handle large virtual addresses, or you can simply print all addresses in hexadecimal notation without using the function. /* * name; memory.c */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> extern char **environ; int global_x = 10; // initialised global variable int global_y; // un-initialised global variable char global_array1[] = "Hello, world!"; // initialised global array char global_array2[10]; // un-initialised global array char *global_pointer1 = "bye!"; // global pointer to a string literal char *global_pointer2; // un-initialised global pointer float global_float = 100.1; // initialised global variable double global_double; // un- initialised global variable #define ONEGB 1073741824 #define ONEMB 1048576 #define ONEKB 1024
Image of page 5
char *addr(unsigned long a) { unsigned long r; // remainder r = (unsigned long) a; int gb = (int) ( r / ONEGB ); r -= gb * ONEGB; int mb = (int) ( r / ONEMB ); r -= mb * ONEMB; int kb = (int) ( r / ONEKB ); r -= kb * ONEKB; int b = (int) ( r ); char *p = malloc(64); sprintf(p, "%4dGB, %4dMB, %4dKB, %4d", gb, mb, kb, b); return p; }
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 15 pages?

  • One '14
  • Virtual memory, Central processing unit, Computer program

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture