Unit 2 Flashcards

1
Q

Distinguish between a program and a process.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the key requirements for operating systems?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between user mode and supervisor mode?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the system bus?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a machine code instruction?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a device controller and what is its purpose?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the advantages of using a buffer for communication?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a process descriptor and why is it needed?

A

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).

17
Q

Under what circumstances will a process scheduler suspend a process?

A

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.

18
Q

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

A

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.

19
Q

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

A

To provide greater fairness and responsiveness to processes requiring interaction.

20
Q

What is the difference between a thread and a process?

A

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.

21
Q

What is a multithreaded operating system?

A

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

22
Q

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");
      thread2.run();
      thread1.start();
      new WhoAmI("Bloggs").start();
   }
}
A

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.

23
Q

What are the two ways to define a thread?

A

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

24
Q

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

A

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.

25
Q

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

A

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

26
Q

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

A

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.

27
Q

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

A

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.

28
Q

When would you want to create a daemon thread?

A

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.

29
Q

What kind of thread is created by invoking main?

A

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

30
Q

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

A

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.