Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSD2_Ex3.doc
Скачиваний:
12
Добавлен:
22.11.2019
Размер:
58.88 Кб
Скачать

Question 1. Preemptive Multitasking

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: It includes a set of memory pages, a set of open file descriptors (if the process does any I/O), a process ID, and several other things

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

Answer: running, runnable, or 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.

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

Answer: The order is 1→2→1→2.

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.

Answer: The order is 2→3→1→4.

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

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]