M362 - 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
  1. Interface between the program and its runtime system (provided by library calls);
  2. Interface between the run time system and the operating system (provided by system calls);
  3. 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

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
10
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
11
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 is an interrupt-driven approach preferable?

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
12
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
13
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
14
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
15
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).

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

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

18
Q

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

A

To provide greater fairness and responsiveness to processes requiring interaction.

19
Q

Suppose that a context switch takes 10 milliseconds and that the quantum is set to 10 milliseconds. Why is this not an efficient value for the quantum? What would be better?

A

In 20 milliseconds, the most the CPU can do is one quantum and one context switch. This means it spends a large proportion (about half) of its time context switching. It may be better to have a larger quantum in this case. For example, if the quantum is set at 30 milliseconds, then in 40 milliseconds the CPU might have done one context switch and spent 75% of its time on executing a process.

20
Q

In the round robin scheme, what is the effect of using a very large quantum?

A

The responsiveness of the system will degrade as the size of the quantum gets larger and individual processes keep a hold on the CPU for longer, starving other processes of time to the point where it becomes noticeable that some processes are not responding.

21
Q

Suppose that the quantum is 1 millisecond and the time to context switch is 10 milliseconds. What is the effect?

A

As the size of the quantum drops below the length of time to perform a context switch, the CPU spends most of its time context switching. In this case, in
100 milliseconds the CPU will have done 9 context switches, and executed processes for only 10 milliseconds – it will thus have spent 90% of its time on context switching.

22
Q

Comparing the round robin scheduling algorithm and the FIFO algorithm, under what circumstances are these more or less equivalent?

A

When the quantum becomes large with respect to service times, most jobs will run to completion without pre-emption, so the round robin algorithm will approximate to a FIFO algorithm. For the example in the text, when the quantum is greater than or equal to 6, the two policies are the same

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

24
Q

What is a multithreaded operating system?

A

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

25
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

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 object referenced 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.

26
Q

What are the two ways to define a thread (in the Java programming language)?

A
A thread can be defined by extending the Thread class or by implementing the
Runnable interface.
27
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.

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

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

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

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

32
Q

What kind of thread is created by invoking main?

A

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

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