operating system

profilemoqwerlop
HW3_Solutions.doc

CMET 331-01 Homework 3

Due at 1:00 pm, Tuesday, October 3, 2017

No credit after 5:00 pm, Monday, October 9, 2017

Solutions

Use Word to process your homework and submit to Blackboard is mandatory.

1. (10 points) Describe the differences among short-term, and long-term scheduling.

Short-term (CPU scheduler)—selects from jobs in memory those jobs that are ready to execute and allocates the CPU to them.

Long-term (job scheduler)—determines which jobs are brought into memory for processing.

Short-term scheduler is invoked very frequently (milliseconds) ( (must be fast)

Long-term scheduler is invoked very infrequently (seconds, minutes) ( (may be slow)

2. (10 points) What is the purpose of system calls?

System calls provide an interface to the services made available by an operating system.

3. (20 points) List 5 states where a process can be during its lifetime, and use an example to explain the 5 states change.

New, running, ready, blocked, exit.

For example, the user invokes the CD record program, a new process is created. When it is running, it will check whether the CD is blank and the data is oversize. If it is true, the process is blocked and waits for the user attention. When it is finished, it will be terminated by user.

4. (20 points) What is the producer consumer problem? Give an example of its occurrence in operating systems

Producer-Consumer Problem also known as the bounded buffer problem. Two processes share a common, fixed-size buffer. One of them, the producer, puts information into the buffer. The other one, the consumer, takes it out.

For example, the local area networking computers share a networking printer. The computers produce printing jobs that are consumed by a printer.

5. (10 points) Describe the actions taken by a kernel to context-switch between processes.

Let us assume process P0 is going to interrupt by P1. First, OS saves P0 state into PCB0. Then OS loads P1 state from PCB1. When OS finishes the execution of P1, it will save P1 state into PCB1, and reloads P0 state from PCB0.

6. (10 points) What is thread? What is motivation to develop the multithreaded processes?

A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack.

A traditional (or heavyweight) process has a single thread of control. If the process has multiple threads of control, it can do more than one task at a time.

7. (10 points) Provide two programming examples of multithreading giving improved performance over a single-threaded solution.

1) A Web server that services each request in a separate thread.

(2) A parallelized application such as matrix multiplication where different parts of the matrix may be worked on in parallel.

(3) An interactive GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third thread monitors performance.

8. (10 points) List the three multithreading models?

Many-to-One

One-to-One

Many-to-Many