Explain how a paging memory management system works

Assignment Help Operating System
Reference no: EM131965285

Assignment - System Software

Task 1

Below is a multithreaded program with two threads. The first thread displays the letter ‘X' on the screen and the second thread displays the letter ‘O' on the screen. The threads are executed on a busy (with several active processes) computer on a time-sharing manner where the execution path of the threads is completely unpredictable.

#include <stdio.h> #include <unistd.h> #include <pthread.h>

// repeat the times (*) operation 100,000 times to slow down the

// execution of the instructions #define RPT 100000

void* print_X() { int i;

float x;

while (1) {

// the multiplication operation below is for consuming some CPU

//time to slow down the execution

for(i=0; i<RPT; i++) { x = 3.1415926*3.1415926; }

printf("X");

}

}

void* print_O() { int i;

float x;

while (1) {

// the multiplication operation below is for consuming some CPU

//time to slow down the execution

for(i=0; i<RPT; i++) { x = 3.1415926*3.1415926; }

printf("O");

}

}

int main () {

pthread_t tid1, tid2;

pthread_create (&tid1, NULL, &print_X, NULL); pthread_create (&tid2, NULL, &print_O, NULL);

// Wait till threads complete. Not really related to this

// question in this assignment. Can be ignored. pthread_join(tid1, NULL);

pthread_join(tid2, NULL);

printf ("\n==========================\n");

}

An instance of the execution of the program produced the output below. Newlines and line numbers were added manually after the output was captured to make it more readable. Based on the information and assumption given above, please answer the following questions:

A. Suppose that Line 1 of the output indicates the corresponding thread completed the full duration of its allocated time slice. Has the thread completed its execution after Line 1?

B. Line 2 is shorter than Line 1. What could be the reason(s)?

C. What could be the possible reasons that caused the output from Line 08 to Line 15?

D. Assuming the program is executed to completion, will the effective execution output of each of the 2 threads (that is the number of Xs and Os printed) be different if the process executing this program is the only active process in the computer? Why and why not?

E. Is it possible to produce exactly the same output (sequence of Xs and Os) with multiple execution instances of the program? Why or why not? Is it possible to have Os printed out before Xs? Why or why not?

01: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

02: OOOOOOOOOOOOOO

03: XXXXXXXXXXXXXXXXXXX

04: OOOOOOOOOOOOOOOOOOO

05: XXXXXXXXXXXXXXXXXX

06: OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

07: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

08: XXX

09: O

10: X

11: O

12: X

13: O

14: X

15: O

16: XXXXXXXXXXXXXXXXXXXXXXXXX

17: OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

18: XXXXXXXXXXXXXXXXXXXXXXX

19: OOOOOOOOOOOOOOOOOOOOOOOO

Task 2

Below is a program that mimics a webpage counter - the counter increases by one for every visit. To count multiple concurrent visits, a new thread is created per every request for a connection from a remote web browser. The variable cnt stores the counter value and is shared by all threads.

#include <stdio.h> #include <unistd.h> #include <pthread.h>

// repeat 100 times to mimic 100 random visits to the page #define RPT 100

//web page visit counter int cnt=0;

void* counter() {

int cntLocalCopy; float r;

cntLocalCopy = cnt;

// mimicking the work of the sever in serving the page to

// the browser

r = rand() % 2000; usleep(r);

cnt = cntLocalCopy + 1;

}

int main () { int i; float r;

pthread_t tid[RPT];

// seed the random number sequence srand(time(NULL));

for (i=0; i<RPT; i++) {

// mimicking the random access to the web page r = rand() % 2000; usleep(r);

// a thread to respond to a connection request pthread_create (&tid[i], NULL, &counter, NULL);

}

// Wait till threads complete. for (i=0; i<RPT; i++) {

pthread_join(tid[i], NULL);

}

// print out the counter value and the number of mimicked visits

// the 2 values should be the same if the program is written

// properly

printf ("cnt=%d, repeat=%d\n", cnt, RPT);

}

The program produced the following output for the corresponding instances of executions.

A. Explain why the counter value is smaller than the number of visits? From the list, the value of cnt is around 60. It is possible for the value be 50 or 70? Why or why not?

B. Modify this program on a platform (Linux or Windows) and programming language of your choice to produce accurate and consistent results.

C. Write a multithreaded program (with two threads - one for writing to a buffer and another for reading from the buffer) on a platform (Linux or Windows) and programming language of your choice. The two threads run concurrently and share the buffer which can be implemented as an array with a maximum capacity of 10 characters. Below is a description of the actions performed by each thread. This can be achieved with a minor modification of the program (avoidance.c on Canvas) from Week 7 lab task.

Thread 1 (writer):
o Reads one character at a time from keyboard.
o Adds the character to the buffer. Thread 2 (reader):
o Reads one character at a time from the buffer.
o Removes the character from the buffer.
o Write the character, together with the number of the remaining characters in the buffer, to the console, e.g., [c:5].
Ensure the threads are properly synchronized so that the reader thread does not attempt to read from an empty buffer and the writer thread does not write into a full buffer. You also need to ensure the buffer is accessed by one of the threads at any given time to maintain the consistency and integrity of data in the buffer.

Task 3

Based on the principles of paging memory management systems, answer the following questions.

A. Briefly explain how a paging memory management system works. Please include the following in your explanation:
- What logical memory addresses are, what physical memory addresses are, and also the relation between the two?
- What level of memory, logical or physical, does the process image of an application occupy?
- What type of memory addresses, logical or physical, does the physical processor (or CPU) operate on?

B. Does a paging memory management system have fragmentation problem at the physical memory (RAM) level? Why or why not? Does a paging memory management system have fragmentation problem at process image level? Why or why not?

C. Can an application running on a computer with a paging memory management system directly access the physical memory? Why or why not?

D. Write down your conclusion about the effectiveness and usefulness of memory defragmentation applications. Your conclusion should be based on the arguments in your answers to the previous questions.

Task 4

Write a program (with the programming language and on the platform of your choice) to demonstrate the memory leak problem. The full program and the program outputs should be included at the end of the report as an appendix.

If you write the program on a platform which has built-in garbage collection mechanism, special care has to be taken to introduce the memory leak problem.

Execute the program until it cannot proceed anymore. You may have to allocate big chunks of memory iteratively to reach to this point quickly. This is even more so if you are running the program on a 64-bit operating system. Based on your observation and your understanding of the principles of a paging memory management system, answer the following questions:

A. How much memory has the program used when reaching the point where it cannot proceed anymore? What is the physical (32-bit or 64-bit) and logical address space of the computer you run this application on? What is the size of the physical memory (RAM) of the computer you run this application on?

B. What type of memory, virtual or physical, is exhausted when there is a memory leak problem with a process?

C. When a process that has a memory leak problem cannot proceed anymore, does it prevent any other program from starting/running due to lack of memory? Does it slow down the whole system?

D. On a platform which has built-in garbage collection mechanism, e.g., .NET and JVM, to a large extent, the memory leak problem can be avoided. Why?

 

Reference no: EM131965285

Questions Cloud

Assume you are the cfo of publicly traded corporation : Assume you are the CFO of a publicly traded corporation. Which of the two options has the higher duration?
The use of assistance other than in-kind benefits : What types of benefits would you advocate for the oppressed group you researched in the first discussion in Unit 1?
Examine at least three significant differences in analysis : Examine at least three significant differences in your analysis, providing specific examples.
What is the approximate cost of the costly trade credit : Suppose one of the suppliers to Seattle Health System offers terms of 3/20, net 60. What is the approximate cost of the costly trade credit offered by supplier
Explain how a paging memory management system works : What could be the possible reasons that caused the output from Line 08 to Line 15 - Explain why the counter value is smaller than the number of visits
Research on an area of cognitive psychology : The Final Paper should be a review of current literature and research on an area of cognitive psychology that is of interest to you.
What is the expected return for given investment : Cy owns investment A and 1 bond B. The total value of his holdings is 1,844 dollars. Bond B has a coupon rate of 7.5 percent, par value of $1000.
A budget based on different workload levels : As sales increase which of the following is a source of funds? A budget based on different workload levels
Consider effects of stress on cognitive functions : For this Discussion, consider effects of stress on cognitive functions. Then think about a time when stress affected your cognitive functions.

Reviews

len1965285

5/1/2018 6:26:52 AM

Late submission of assignments without an approved extension will result in a penalty of 5% reduced marks from the total available, per calendar day late. An assignment submitted over 7 days late will not be accepted. Submissions are through Moodle (http://learnonline.canberra.edu.au/) only. No other forms of submission will be accepted. If a student chooses to submit his/her assignment via the Internet off the campus, it is the responsibility of the student to guarantee the accessibility of the Internet. Not being able to access to the Internet at the location which is off the campus is not an excuse for extension. You should not repeat the question text to avoid URKUND warning for high similarity due to repeated question text. Listing question level and question number is enough.

len1965285

5/1/2018 6:26:37 AM

Assignment submission contributes 5% to the unit assessment and is due on Friday at 11:55pm AEST in Week 12. The Assignment Evaluation Test (15%) will be due in Week 13 during tutorials. One should plan and complete his/her assignment before the deadline. Submissions are through UCLearn (http://uclearn.canberra.edu.au/). After uploading your assignment, please DO NOT FORGET to click the submit button; otherwise, your submitted assignment may remain as a draft.

Write a Review

Operating System Questions & Answers

  Implementation of algorithms for process management

The Shortest Job Next (SJN) algorithm queues processes in a way that the ones that use the shortest CPU cycle will be selected for running rst.

  Develop a user mode command interpreter

Develop a user mode command interpreter which support list-short.

  Memory allocation in operating system

Analysis and implementation of algorithms for memory allocation in operating system, Explain First- t and best- t methods are used in memory allocation in operating systems.

  Stand alone child process

Forking the child process

  Write a multi-threaded program

Write a multi-threaded program to solve producer and consumer problem

  Marginal and average cost curves

n a competitive market place (pure competition) is it possible to continually sell your product at a price above the average cost of production.

  Simulating operating systems scheduling

Simulate the long-term scheduler, the short-term scheduler and the I/O scheduler of the computer using the First-Come-First-Serve algorithm.

  Issues with trusted platform module

Research paper discussing the issues with Trusted Platform Module (TPM)

  Threads

Explain a complication that concurrent processing adds to an operating system.

  Design and programming

Use the semaphore methods to control the concurrency of the solution

  Virtual machines

Virtual machines supported by a host operating system

  Discuss an application that benefits barrier synchronization

Discuss an application that would benefit from the use of barrier synchronization

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd