CS 620

Assignment 1 Solutions

Due Date: 02/07/2008 (Thursday)

1. (8 points)

Answer the following questions about time-sharing:

[Answer]

(a) What is time-sharing? (1 point)
Time sharing is using scheduling and multiprogramming to provide an economical interactive system of two or more users. The CPU switches rapidly from one user to another.
(b) What are the main advantages of a time-share system? (1 point)
The main advantages of a time-share system are interaction with computer while program is running, short response times(usually less than 10 seconds).
(c) How is time-sharing usually implemented? (2 points)
Each user is given a brief time-slice for her job, in round-robin fashion. Her job continues until the time-slice ends. Then her job stops, until it is her turn again.
(d) Under what circumstances would a user be better off using a time-sharing system, rather than a personal computer or single-user workstation? (2 points)
When there are few other users, the task is large, and the hardware is fast, time-sharing makes sense. The full power of the system can be brought to bear on the user's problem. The problem can be solved faster than on a personal computer. Another case is when there are lots of other users needing resources at the same time.
(e) How does a time-share system differ from a real-time system? (2 points)
In time-sharing, fast response is desirable, but not required. In real-time systems, processing must be completed within certain time constraints appropriate for the system.

2. (4 points)

Answer the following questions about command interpreter:

[Answer]

(a) What are command interpreters?
A command interpreter (also shell, command language interpreter) is a computer program that reads lines of text entered by a user and interprets them in the context of a given operating system or programming language. It reads commands from the user or from a file of commands and executes them, usually by turning them into one or more system calls.
(b) What is the purpose of the command interpreter?
It is a fundamental approach for users to interface with the operating system.
(c) Why is it usually separate from the kernel?
It is usually not part of the kernel since the command interpreter is subject to changes. User level programs are much more easy to write and debug (the user level software environment is more friendly like better debuggers, and any bugs will not cause great problems such as reboot, loss of data, crashing system which in turn causes down time, etc).
(d) Would it be possible for the user to develop a new command interpreter using the system-call interface provided by the operating system?
It is possible to write a new command interpreter using operating system's system-call since a command interpreter can be separate from the OS and it's function is basically turning lines of text into system calls.

3. (4 points)

Describe the difference between symmetric and asymmetric multiprocessing. What are the advantages and disadvantages of multiprocessor systems?

[Answer]
Symmetric multiprocessing treats all processors as equals, and I/O can be processed on any CPU. Asymmetric multiprocessing has one master CPU and the remainder CPUs are slaves. The master distributes tasks among the slaves, and I/O is usually done by the master only.

Multiprocessors can save money, by not duplicating power supplies, housings, and peripherals. They can execute programs more quickly, and can have increased reliability. They are also more complex in both hardware and software than uni-processor systems.

4. (4 points)

What is the main advantage of multiprogramming? At any given time, the CPU executes a single process, how does multiprogramming improve CPU utilization? what is the difference between multiprogramming and multiprocessing?

[Answer]
Multiprogramming makes efficient use of the CPU by overlapping the demands for the CPU and its I/O devices from various users. It attempts to increase CPU utilization by always having something for the CPU to execute.

In a multiprogramming system, the operating system organizes jobs in such a way that the CPU is never idle. If one job, is waiting for some I/O task to complete, the CPU will switch over to next job instead of sitting idle. Thus, even if only one job executes at a time, CPU utilization is obtained by keeping the CPU busy at all times.

In multiprogramming, several programs are in memory concurrently; the system switches among the programs for efficient processing, and minimal idle time. Multiprocessing is related to multiprocessor systems which have two or more processors in close communication, sharing the computer bus and the clock.

5. (6 points)

A computer has a cache, main memory, and a disk. If a word is in the cache, 8 ns are required to access it. If it is in main memory, but not in cache, 70 ns are needed to load it into the cache. and then the reference is started again. If the word is not in main memory, 8 milliseconds (1 millisecond = 10^6 ns) are required to fetch it from disk, followed by 70 ns to get it into the cache. If the cache hit ratio is 0.6, and the main memory hit ratio is 0.8, what is the average access time? You must show how you arrived at your answer. If you just write down your final answer, you will not receive any credit.

[Answer]

Ta = total access time

Hc = cache hit ratio

Tc = Time to access cache

Hm = main memory hit ratio

Tm = Time to load data into the cache from main memory

Td = Time to load data into the cache from disk

 

Hc = 0.6; Hm = 0.8;

Tc = 8ns; Tm = 70ns; Td = 8ms;

 

Case 1: the word is in the cache:  Hc*Tc

Case 2: the word is not in cache, but in memory: (1-Hc)*Hm*(Tc+Tm)

Case 3: the word is not in cache, not in memory, but on disk: (1-Hc)*(1-Hm)*( Tc+Tm+Td)

Ta = Case 1 + Case 2 + Case 3

= Hc*Tc + (1-Hc)*Hm*(Tc+Tm) + (1-Hc)*(1-Hm)*( Tc+Tm+Td)

= Tc + (1-Hc)*Tm + (1-Hc)*(1-Hm)*Td

= 8 + (1-0.6)*70 + (1-0.6)*(1-0.8)*8*10^6

= 640036 ns

6. (4 points)

What are virtual machines? Explain the relationship between the Java programming language and the virtual machine concept.

[Answer]
Some systems are designed as a sequence of layers. The virtual machine concept takes the layered approach and treats both the kernel of the operating system and the hardware as if they were all hardware. Even other operating systems may be loaded on top of this virtual machine. All Java programs can be run on any operating system that implemented the Java Virtual Machine, because the JVM abstracts the underlying system to the Java program, providing an architecture-neutral interface.

7. (6 points)

A main memory system consists of a number of memory modules attached to the system bus. When a write request is made, the bus is occupied for 100 nanoseconds (ns) by the data, address, and control signals. During the same 100 ns, and for 500 ns thereafter, the addressed memory module executes one cycle accepting and storing the data. The operation of the memory modules may overlap, but only one request can be on the bus at any time. Assume that there are eight such modules connected to the bus. What is the maximum possible rate (in words per second) at which data can be stored? Explain you answer.

[Answer]
Each request takes 100ns on the bus, followed by another 500ns to complete the operations. The bus is free after the first 100ns of the request.   Therefore 6 modules can be addressed in 600ns after which the first module will be completing the operation. Therefore we have enough modules to handle the peak transfer rate of the bus. The peak transfer rate would therefore be the same as that of the bus i.e, 10^9/100 = 10^7 requests per second. We can ignore the 5 incomplete requests.

8. (4 points)

Writing an operating system that can operate without interference from malicious or undebugged user programs requires some hardware assistance. Describe three hardware tools used in computers as protection mechanisms.

[Answer]

These three hardware tools are dual-mode, timer and main memory protection.

The dual mode of operation provides a mechanism for protecting the operating system from errant users - and errant users from one another. This protection is accomplished by designating some of the instructions that may cause harm as privileged instructions. The hardware allows privileged instructions to be executed only in kernel mode. Users execute in user-mode.

Timer management is one of the privileged instructions. A timer is set by the OS before any user program is allowed to execute. When the timer expires, the OS takes control of the CPU.

Memory protection is handled by the base and bound register. The values of these registers are set by the OS before allowing a program to execute. The executing program can only access memory within the base and bound limits.

9. (4 points)

Answer the following questions about distributed systems:

[Answer]

(a) What are distributed systems? (1 point)
Distributed systems distribute computation among independent computers linked by a network. They provide the users with access to the various resources that the system maintains and the OS is responsible for distributing workload. They have a high degree of transparency.
(b) Why are distributed systems desirable? (1 points)
Distributed systems can provide resource sharing, computation speedup, increased reliability, and the ability to communicate with remote sites.
(c) Distinguish between distributed systems and network. (2 points)
A network System is a collection of software and associated protocols that allows a set of autonomous computers, which are interconnected by a computer network, to be used together in a convenient and cost-effective manner. Each host runs its own non-network operating system. Network system is not very transparent and users are largely responsible for taking advantage of the resources on the network.

A distributed System is a single, homogeneous operating system controls all hosts on the network, and the network itself. It is very transparent and the OS is responsible for distributing workload and taking advantage of the resources.

10. (3 points)

We have stressed the need for an operating system to make efficient use of the computing hardware. When is it appropriate for the operating system to forsake this principle and to "waste" resources? Why is such a system not really wasteful?

[Answer]
Single-user systems should maximize use of the system for the user. A GUI might "waste" CPU cycles but it optimizes the user's interaction with the system.

11. (3 points)

What are the differences between a trap and an interrupt? Can traps be generated intentionally by a user program? Explain.

[Answer]
An interrupt is a hardware generated change-of-flow within the system, while a trap is a software-generated interrupt. An interrupt can be used to signal the completion of an I/O to obviate the need for device polling. A trap can be used to call operating system routines or to catch arithmetic errors.

Of course traps can be generated by a user program since traps are created by a software and a software is a program written by a user. For example, dividing a number by 0 will cause a trap.

Return to the CS 620 Home Page