关键词 > COMPSCI340&SOFTENG370

COMPSCI 340 & SOFTENG 370 Operating Systems Second SEMESTER, 2017

发布时间:2022-11-06

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMPSCI 340 & SOFTENG 370

Second SEMESTER, 2017

COMPUTER SCIENCE & SOFTWARE ENGINEERING

Operating Systems

Question 1

[1 mark] Which of the following statements is FALSE?

(a) Dividing operating systems into layers or rings of software can help to reduce errors and make testing easier.

(b) Early personal computer operating systems forced programmers to access hardware through specific system calls.

(c) System calls can be used to give safe access to devices ensuring that the devices are used properly and that contention is controlled.

(d) Direct control of hardware by user level processes is usually regarded as dangerous.

(e) Passing control through several software layers to carry out a task at the hardware level can slow a process down.

Question 2

[1 mark] In class which of the following was used to illustrate one way of structuring the design of operating systems?

(a) Ogres

(b) Rockets

(c) Dinosaurs

(d) Rocks

(e) Donkeys

Question 3

[1 mark] Which of the following was NOT important in the development of batch operating systems?

(a) Protected memory

(b) Interrupt handling

(c) Disk drives

(d) Graphical user interfaces

(e) Privileged instructions

Question 4

[1 mark] The earliest personal computer operating systems were most like which of the following types of operating systems?

(a) Real-time systems

(b) Resident monitors

(c) Multitasking systems

(d) Batch systems

(e) Time sharing systems

Question 5

[1 mark] Which of the following is FALSE?

(a) Paravirtualization requires changes to the host operating system.                          (b) VirtualBox is an example of a type 2 hypervisor or virtual machine manager.     (c) Virtual machines can be implemented using the trap and emulate mechanism.    (d) Hardware assistance is of benefit when implementing efficient virtual machines. (e) A major use of virtual machines is in large data centres.

Use the following code from assignment 1 for the next 2 questions.

Thread newThread;

Thread mainThread;

struct sigaction setUpAction;

void associateStack(int signum) {

Thread localThread = newThread;

localThread->state = READY;

if (setjmp(localThread->environment) != 0) {

(localThread->start)();

localThread->state = FINISHED;

switcher(localThread, mainThread);

}

}

void setUpStackTransfer() {

setUpAction.sa_handler = (void *) associateStack;

setUpAction.sa_flags = SA_ONSTACK;

sigaction(SIGUSR1, &setUpAction, NULL);

}

Question 6

[1 mark] When is the associateStack function called? Choose the answer which directly leads to the actual call.

(a) When the currently running thread has finished.

(b) When a new thread is created.

(c) When changing from one thread running to the next thread running.

(d) When the SIGUSR1 signal is received by the process. (e) When the process starts running.

Question 7

[1 mark] Why is the line: setUpAction .sa_flags = SA_ONSTACK; necessary?

(a) It is used to associate an alternate stack with the signal handler and hence the thread. (b) It is required for all signal handlers.

(c) It is not required but it makes the process run more efficiently.

(d) It says that the action is to be run on the stack rather than in the heap.

(e) It is used to associate the normal runtime stack with the signal handler and hence the thread.

Question 8

[1 mark] In the original  threads3 .c file from assignment 1 there were the following lines:

signalsOff();

result = rand();

signalsOn();

What was the reason for the calls to turn signals off before calling the rand function and then to turn them on again afterwards?

(a) If the rand function is interrupted it can produce values which are not uniformly random. (b) The rand function is async signal safe and so signals must be off when it is called.

(c) If the rand function is interrupted it can cause the program to lock up.

(d) The rand function never returns if signals are on.

(e) This stops hackers sending signals to the process to force rand to produce a known sequence of

numbers.

Here is some output from Part3 of assignment 1. Use this for the next 2 questions

Thread States

=============

threadID: 0 state:finished

threadID: 1 state:running

threadID: 2 state:ready

bye

Thread States

=============

threadID: 0 state:finished

threadID: 1 state:ready

threadID: 2 state:running

Question 9

[1 mark] Which of the following best explains what is happening here?

(a) Thread 1 is switched to, it runs for a short time, it is preempted and thread 2 is switched to. (b) There is not enough information in this output to say what is happening.

(c) Thread 1 is switched to, it finishes and thread 2 is switched to.

(d) Thread 1 is running, it is preempted before it can do anything, thread 2 is switched to. (e) Thread 1 and thread 2 swap places in the ready queue.

Question 10

[1 mark] Which thread produces the output "bye"?

(a) Thread 0

(b) Thread 1

(c) There is not enough information to say.

(d) None of the threads, it is the main function. (e) Thread 2

Question 11

[1 mark] A fiber is a construct used in some operating systems very similar to a thread but without            preemption i.e. fibers multitask cooperatively. Windows has fibers implemented on top of threads. Which of the following statements about fibers is FALSE?

(a) Each process can only run one fiber at a time.

(b) Fibers are regarded as more lightweight than threads.

(c) Fibers can be implemented at the user level.

(d) A badly written fiber could stop other fibers in the same thread from running.             (e) Because they multitask cooperatively fibers can be written without the need for locks.

Question 12

[1 mark] Which of the following is FALSE?

(a) The runnable state includes both ready and running states.

(b) A zombie is a Unix process which has finished but its parent hasn’t waited for its result yet. (c) Windows 10 normally creates a new process by copying an existing process.                        (d) Processes can transition directly from the waiting state to the finished state.

(e) Most processes spend most of their time waiting.

Question 13

[1 mark] How many processes does the following program create (including the initial process)?

#include <stdio .h>

#include <unistd .h>

void main() {

int i = 0;

while (i < 3) {

if (fork() != 0) {

i++;

}

i++;

}

}

(a) 5

(b) 3

(c) 6

(d) 8

(e) 4

Use this information for the next 3 questions.

Three ready processes P1, P2 and P3 have burst times of 12, 6 and 4 milliseconds.

Question 14

[1 mark] What is the average waiting time for these processes if they are scheduled first come first served in the order P1, P2 then P3?

(a) 7 1/3 milliseconds

(b) 12 milliseconds

(c)  10 milliseconds

(d) 5 milliseconds

(e) 6 milliseconds

Question 15

[1 mark] What is the shortest possible average waiting time for the 3 ready processes?

(a) 5 milliseconds

(b) 10 milliseconds

(c) 4 milliseconds

(d) 4 2/3 milliseconds

(e) 5 1/3 milliseconds

Question 16

[1 mark] Using round-robin scheduling in the order P1, P2, P3 which of the following timeslices gives   the LARGEST average wait time? N.B. These numbers are the timeslices not the average waiting times.

(a) 4 milliseconds

(b) 5 milliseconds

(c) 6 milliseconds

(d) 3 milliseconds

(e) 2 milliseconds

Question 17

[1 mark] Which of the following is FALSE?

(a) The problem of priority inversion is impossible to solve.

(b) The rate monotonic scheduling approach uses fixed priorities.

(c) One way to prevent indefinite postponement is to use process aging.

(d) Priorities can make otherwise feasible real time schedules impossible.

(e) Static priorities can cause starvation.

Question 18

[1 mark] Which of the following statements concerning the Unix operating system is FALSE?

(a) Files which are open in the parent are also initially open in the child process.         (b) A process with a priority of 20 has a better priority than a process with priority 10.

(c) Signals can be used to notify processes when they have done something wrong.

(d) The fork system call is usually followed by a call to exec.

(e) A waiting process is placed on a queue associated with the kernel address of the resource the process is waiting for.

Here is a very simple attempt at implementing a lock:

lock:

while locked

end

locked = true

unlock:

locked = false

Question 19

[1 mark] Which of the following statements about the above lock code is FALSE?

(a) The reason it doesn't work is because of instruction reordering at the processor level. (b) There is nothing to stop a thread calling unlock even when it does not hold the lock.

(c) It doesn't work, multiple threads could gain the lock simultaneously.

(d) It is unfair, there is no guarantee a thread will progress through the lock.

(e) It wastes CPU cycles checking the value of the locked variable.

Question 20

[1 mark] Which of the following is the best definition of an atomic instruction?

(a) The instruction has no operands and changes state instantaneously.

(b) The instruction stops all other processes or threads from working until it has completed.

(c) As an atomic instruction executes the operand values are only accessible from within privileged code such as the kernel.

(d) The instruction can be broken down into smaller sub-atomic instructions; interrupts only occur at the end of these sub-atomic instructions.

(e) The instruction executes without its operands being accessible by other threads until the

instruction has completed.

Question 21

[1 mark] Which of the following best describes priority inversion and why it occurs?

(a) A process X with better priority is blocked waiting for a resource held by a process Y with worse priority because process Y is not scheduled as there are other runnable processes with worse        priorities than Y.

(b) A process X with worse priority is blocked indefinitely by a process Y with better priority because process Y has locked a resource needed by process X.

(c) A process X with better priority is blocked waiting for a resource held by a process Y with worse priority because the resource is locked by process Y.

(d) A process X with better priority is blocked waiting for a resource held by a process Y with worse priority because process Y is not scheduled as there are other runnable processes with better        priorities than Y.

(e) A process X with worse priority has its priority improved because a process Y with better priority is waiting for a resource held by process X.

Question 22

[1 mark] Which of the following statements about semaphores is TRUE?

(a) Semaphore operations do not have to be atomic.

(b) When returning a resource with no process waiting the semaphore value is incremented.

(c) Semaphore waits and condition variable waits are the same.

(d) Semaphores are more powerful than monitors and locks.

(e) None of the above.

Question 23

[1 mark] Which of the following concurrency constructs requires code to use specific entry points?

(a) lock-free algorithms

(b) semaphore

(c) mutex

(d) monitor            (e) memory barrier

Question 24

[1 mark] Which of the following is NOT necessary for deadlock to occur?

(a) Processes can hold a resource while waiting for another resource.

(b) A process is waiting for a resource held by a process with a lower priority.

(c) Only the process currently holding a resource can release it.

(d) There is a circle of processes each waiting for a resource held by another process in the circle. (e) Resources can only be used by one process at a time.

Question 25

[1 mark] Which of the following statements about the Dining Philosophers’ problem is FALSE?

(a) The number of forks is always 1 more than the number of philosophers.

(b) The Dining Philosophers’ problem is commonly used to demonstrate different solutions to the concurrency problem.

(c) Simply locking each fork as it is picked up can easily lead to deadlock.

(d) The simultaneous wait solution to the Dining Philosophers’ problem solves the problem of deadlock.

(e) If there are n philosophers, only allowing n-1of them to try to eat at a time is a feasible solution

to the problem.