Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Question 1. Preemptive Multitasking






Exercise 3

In this section you will use a Timestamp program and a graphical interface to examine how preemptive processing works.

Before executing the program, answer the following questions in the context of an operating system:

a. What is a process?

Answer: A process is an instance of a running program.

b. What does a process include?

Answer: Includes a set of memory pages, a set of open file descriptors, a process ID, and several other things.

c. Name the possible states that a process can be in.

Answer: running, runnable and blocked.

d. What is a thread?

Answer: A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently of everything else that might be happening.

e. Why are threads useful?

Answer:

1) Less time to create a new thread than a process, because the newly created thread uses the current process address space.

2) Less time to terminate a thread than a process.

3) Less time to switch between two threads within the same process, partly because the newly created thread uses the current process address space.

4) Less communication overheads -- communicating between the threads of one process is simple because the threads share everything: address space, in particular. So, data produced by one thread is immediately available to all the other threads.

Now let us try using the Timestamp program and run two threads.
Right-click on Timestamp.exe and save program in drive C. This program should be executed in the Windows command console. Open the Windows command console by clicking on the Start menu on desktop, and then select Run... Type " cmd" in the text field and click OK. At the prompt C: \, type " Timestamp –i 500000 –p 2 > Output.out"; press ENTER.

Note: -i specifies the number of work cycles, and -p specifies the number of threads to run.

Now use the graphical interface to see the output.
Right-click on Graph.exe and save the program in Drive C. Open the program. If Graph.exe does not run, refer to Appendix A. Running a Visual Basic File for instructions. Once Graph.exe is opened, click Select Data File, and choose the file Output.out in drive C.

Note that the horizontal axis is the number of work cycles. Each thread is distinguished by a different color. The gray areas indicate that the system is not running the given threads. A legend for the threads is displayed at the bottom of the graph.

 

 

f. Capture a screen shot of the graphical output.

 

List the order in which the threads are being executed.

1> 2> interrupt> 1> interrupt> 1> interrupt> 1> 2

g.

 

h. What is a context switch? How do you know a context switch occurred from the graph?

Answer: Switching the CPU to another process requires saving the state of the old process and loading the saved state for the new process. This task is known as a context switch. I know a context switch occurred when an interrupt displays on the graph.

i. What activities are performed by the processor during a context switch?

Answer: An interrupt is occurring

j. Explain what is happening in terms of preemptive multitasking and what effect it has to the user.

Answer: The processor also assigns priorities to different types of interrupts. Low-speed devices like the keyboard have low priority. High-speed devices like a SCSI disk have high priority because they need a rapid response in order to function optimally. It avoids losing information.

k. An interrupt indicates that the thread is not being run and should therefore be followed by a gray gap. How does the kernel handle an interrupt?

Answer: The input device sends to the processor a signal called an IRQ (interrupt request). When the processor receives this signal, it stops executing the application program (a Web page editor for example), making note of the address of the last instruction executed. Then, it jumps to the address of the keyboard interrupt handler, and starts executing the instructions it finds there.

Try using more than two threads.
At the Windows command prompt C: \, type “ Timestamp –i 500000 –p [enter the number of threads to run (less than 10)]” and press ENTER.

 

l. Copy and paste the graphical output.

m. List the order in which the threads are being executed.

7> interrupt> 7> interrupt> 2> 4> 10> 4> 10> 8> 10> 8> 9> 2> 8> 2> 6

n. Consider a set of three processes that are executed to completion. Process A takes 6 seconds, Process B takes 3 seconds, and Process C takes 5 seconds. About how long would it take for all the processes to be completed using preemptive multitasking, more than 14 seconds, less than 14 seconds, or exactly 14 seconds? Explain your answer.

Answer: More than 14 seconds. Because context switch takes a little time.

Now investigate your own system.

o. How much RAM (main memory) does your machine have? Show proof of your answer by submitting a screenshot of the display from which you inferred your answer.

Answer: 0.99G (1014 MB).

Launch Microsoft Word if it is not already launched.

p. How many threads does Microsoft Word launch? (Refer to 3.1.4 Lab: The Task Manager.) Show proof of your answer by submitting a screenshot of the display from which you inferred your answer.

Answer: 5 threads.

q. How much memory does Microsoft Word consume? Show proof of your answer by submitting a screenshot of the display from which you inferred your answer.

Answer: 32, 188K


Question 2. Virtual Memory

In this section, you will use a program demonstrating how virtual memory is used.

a. How does virtual memory work using a page table?

Answer: In virtual mode, every address is " translated" into a physical memory location by means of a page table. For each page in the virtual address space, the page table gives the real address in RAM where the page is located.

 

b. What is the primary purpose of virtual memory?

Answer: In order to increase program flexibility.

 

c. List three advantages of using virtual memory when executing a program.

Execute the Page Replacement Simulation program.

Answer:

1) The most important is process isolation.

2) Another advantage of virtual memory is that the address space the processes see can actually be larger than the physical memory available.

3) We need not worry about how much physical memory is on the machine. We have an entire virtual address space to use as they like, and the kernel takes care of the implementation details.


Click on Paging.exe to run the application. Refer to Appendix A. Running a Visual Basic File if Paging.exe does not run.

Notice the top of the program window indicates the number of request and total page faults. The table on the left represents RAM and the one on the right represents the hard disk. The order of requests is set at default. You can also enter your own order of requests. To change the speed of the simulation, you can use the speed adjuster at the bottom-left of the program window. Each time you click on Stop or Pause, the simulation ends after one complete memory access.

Start the program using the default queue of requests.

c. Describe what is happening for the first seven requests step-by-step for the default order of requests.

Answer: Six page faults occurred. It means five requests is in virtual memory. The computers first take it to RAM and then send it to CPU.

 

d. When does a page fault occur, and how does the kernel handle a page fault?

e. Answer: The address translation circuitry checks the page table, finds the " not in RAM" marker, and generates a page fault. This is a kind of interrupt. The processor stops executing the user program and gives control to the kernel. The kernel looks at certain status registers to figure out where the page fault came from and says, " Oh, this process wants access to its virtual page seven. I will get some RAM here and load in page seven of the program. Now I will fix update the page table, and I will let the program the instruction again." So, control is returned to the user program, and the program continues as if nothing unusual had happened.

f. Enter a sequence of eight requests in place of the default order of requests in the program that would cause four page faults.

Answer: 2, 3, 4, 1, 2, 1, 3, 4

g. In what case is it undesirable to use virtual memory?

Answer: The speed is very low.

h. Given a total paging file size of 267MB, and a RAM of size 256MB. Your applications are currently taking up 500MB of memory. How would you run an application that consumes 100 MB of memory?

Answer: Expand the virtual memory.


Поделиться с друзьями:

mylektsii.su - Мои Лекции - 2015-2024 год. (0.01 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал