Unit 2 Flashcards Preview

My M362 Unit SAQs > Unit 2 > Flashcards

Flashcards in Unit 2 Deck (30):

Distinguish between a program and a process.

A program is static and an abstraction of the desired program behaviour.


A process is the dynamic representation of a program, that is, it represents the program’s execution.


What are the key requirements for operating systems?

There are three key requirements for operating systems:
1 Keeping systems busy.
2 Keeping users productive (responsiveness).
3 Sharing resources between users and processes.


Why is compiled code typically not portable from one platform to another?

Compilation creates platform-dependent machine code, targeted at a particular processor, therefore it is not portable.


What is the difference between user mode and supervisor mode?

Certain processor instructions, known as privileged instructions, cannot be executed when the processor is in user mode.

User programs run in user mode and request supervisor mode instructions, where necessary, via library calls.


What is the purpose of the system bus?

The system bus allows the processing unit to communicate with devices through their respective device controllers.


What is the relationship between registers, main memory, disk storage, and cache?

Registers are storage locations inside the CPU which hold a machine instruction and the data that it works on during a fetch–execute cycle.

A Cache is similar to main memory, but is smaller and can be accessed by the CPU much faster than normal main memory. It is therefore used to hold data that is likely to be frequently accessed by the CPU.

Main memory consists of the storage locations for holding machine instructions and
data that the CPU will transfer into its registers as part of the fetch–execute cycle.

Disk storage is a device attached to a computer that holds files and programs which must be loaded into main memory before they can be worked on or executed. It is a form of persistent (non-volatile) storage.


What is a machine code instruction?

A machine code instruction is the fundamental instruction that a CPU works with and executes without interruption.


What are the three software interfaces that link a user program to a device controller?

The three interfaces that link a user program to a device controller are:

  • the interface between the program and its runtime system (provided by library calls);
  • the interface between the runtime system and the operating system (provided bysystem calls);
  • the interface between the operating system and the device controller (provided by device calls).


How does an operating system interface to a device, and what is the role of a device driver?

An operating system provides a high-level interface to hardware that hides the specific details of how each device is programmed. Within the operating system, it is the device driver for a particular device that knows how to interface with the device controller and translates high-level requests into lower-level interactions with the device.


What is a device controller and what is its purpose?

A device controller has its own :

  • simple processor,
  • memory and
  • registers,

so that it can execute in parallel with the CPU and provide two-way communication with a hardware device. The operating system interfaces with the device controller via a device driver making device calls.


What is an interrupt? What actions must an operating system take when an interrupt occurs?

An interrupt is a mechanism by which a device or software signals to the processor that some event has occurred. If the interrupt is of high enough priority, the processor must perform a context switch. The processor must then execute a routine to deal with the interrupt (such as transfer data to a device) before resuming the original process.


What are the advantages and disadvantages of handling devices by a polling scheme compared with an interrupt-driven approach? In what kinds of system does the application dictate the approach to be taken?

In a polling scheme every device is guaranteed to be served within a specified time, but prioritisation is difficult.

In an interrupt-driven system, urgent requests can be dealt with very quickly by assigning priorities to types of request, but non-urgent requests may have to wait for a long time while more urgent requests are dealt with.  Interrupt-driven systems are preferable in interactive systems and real-time systems, which require immediate responses to critical events.


What happens if a user program attempts to execute a privileged instruction (via a system call)?

A supervisor call interrupt is generated. A context switch takes place to put the processor into supervisor mode and execute the interrupt handler. At this point the interrupt handler may decide to execute the user code or not. Subsequently the processor returns to running in user mode via another context switch.


Why is it useful to have a system of priorities associated with interrupts?

Prioritised interrupts enable the operating system to react more quickly to some events than others.


What are the advantages of using a buffer for communication?

A buffer can be used to smooth out differences in operating speeds of the sending and receiving processes or devices, so that communication is more efficient – given a large enough buffer neither the sending nor the receiving process (or device) will need to wait after depositing data in the buffer before proceeding with other work.


What is a process descriptor and why is it needed?

A process descriptor is a data structure storing information about the context of a process in a form that allows the process to be paused and restarted later. Storing information about the context of a process is necessary because the system normally can execute only one process at a time. To keep the system busy and responsive, and to prevent processes from interfering with each other, we need to be able to pause and restart processes (in other words to perform context switching).


Under what circumstances will a process scheduler suspend a process?

Usually a process is suspended when it is Blocked and other processes might be made Runnable by being admitted, or by being activated from a Runnable Suspended state. However, a Runnable process may also be suspended according to scheduler priorities and the availability of other high-priority processes to run.


Explain how the timer interrupt mechanism together with the process scheduler assists in achieving multitasking on a single processor.

A timer interrupt can be used by a scheduler to decide points in time at which to apply a selection function, that is, to pre-empt a running process. This may result in a decision to allow a different process to run from the one currently running. At this point the scheduler can initiate a context switch to make the processor deal with another task until the next switch should take place.


Why is a pre-emptive scheduling policy preferred in interactive systems?

To provide greater fairness and responsiveness to processes requiring interaction.


What is the difference between a thread and a process?

Threads (lightweight processes) are a unit of dispatching but not of resource management. Processes are a unit of both dispatching and resource management. In particular, threads share an address space (memory) through which they can communicate ‘cheaply’ as compared to processes. This is because when there is a context switch it is unnecessary to change resource information, thereby reducing the time taken for the switch. A heavyweight process has its own copy of all resources and so context switches have a larger overhead.


What is a multithreaded operating system?

A multithreaded operating system is one that supports the execution of lightweight processes.


Assuming the same WhoAmI class shown earlier, how many threads does the following code create within the Java Virtual Machine?

public class ThreadTester2
   public static void main(String[]args)
      WhoAmI thread1 = new WhoAmI("Joe");
      WhoAmI thread2 = new WhoAmI("Sue");
      new WhoAmI("Bloggs").start();

This code creates three threads: the thread started by invoking main, the thread created by invoking start on the Thread object referenced by thread1, and the anonymous thread we passed the value "Bloggs" to. Invoking run on the Thread objectreferenced by thread2 does not create a new thread. The run method would be executed within the main user thread, like a normal method call, and would be completed before thread1.start()is invoked.
In addition, the Java Runtime will have created other threads, such as the garbage collection thread.


What are the two ways to define a thread?

A thread can be defined by extending the Thread class or by implementing the Runnable interface.


When a thread is executing, does it always keep executing until it gets to the end of its code without interruption?

No, a thread is unlikely to keep executing until it comes to the end of its code. In all likelihood the thread will only have access to the CPU for a short part of its execution before it is stopped and another thread is given an opportunity to run.


How do you tell the system that you want to set a thread running?

To set a thread running after creating an instance of a threaded class, the method start can be invoked.


When would you typically want to define a thread by implementing Runnable rather than extending Thread?

There are many occasions when a threaded class will be inheriting from another class, for example JFrame. As Java does not allow multiple inheritance, if such classes require threading, the only way to do this is by implementing the Runnable interface. However, it is generally best to implement Runnable when you do not require an inheritance relationship with Thread.


How do you define, create and start a thread using Runnable?

To define, create and start a thread using Runnable, first implement the interface Runnable, which requires implementing the run method required by the interface. Then create an instance of the Runnable class and create a new Thread object using the Thread constructor that takes a Runnable object as an argument. The Thread object thus created can be started in the usual way, by invoking the start method.


When would you want to create a daemon thread?

You may want to create a daemon thread when the thread is intended to run without intervention, or when it is safe for the virtual machine to exit whether or not the thread has completed running. This is often the case for threads that do background work.


What kind of thread is created by invoking main?

Invoking main creates a user (non-daemon) thread.


Under what circumstances should a Java thread relinquish a processor? How could it do so?

A thread may initiate a context switch when it is waiting for an event or simply to allow other threads a chance to run, by invoking the yield method, or the sleep method.