Question prep

advertisement
INTRODUCTION
1) What are the three main purposes of an operating system?
2) Consider the various definitions of operating system. Next, consider whether the
operating system should include applications such as Web browsers and mail
programs. Argue both that it should and that it should not, and support your answers.
3) How does the distinction between kernel mode and user mode function as a
rudimentary form of protection (security) system?
4) Which of the following instructions should be privileged? And why
a) Set value of timer.
b) Read the clock.
c) Clear memory.
d) Issue a trap instruction.
e) Turn off interrupts.
f) Modify entries in device-status table.
g) Switch from user to kernel mode.
h) Access I/O device.
5) Some CPU s provide for more than two modes of operation. What are two possible
uses of these multiple modes?
6) What is the purpose of system calls?
7) What are the five major activities of an operating system with regard to process
management?
8) What is the purpose of the command interpreter or shell? Why is it usually separate
from the kernel?
9) What system calls have to be executed by a command interpreter or shell in order to
start a new process?
10) Discuss a major complication that concurrent processing adds to an operating system.
11) When a process creates a new process using the fork() operation, which of the
following state is shared between the parent process and the child process?
a) Stack
b) Heap
c) Shared memory segments
12) Provide two programming examples in which multithreading provides better
performance than a single-threaded solution.
13) Provide two programming examples in which multithreading does NOT provide
better performance than a single-threaded solution.
14) What are two differences between user-level threads and kernel-level threads? Under
what circumstances is one type better than the other?
15) What resources are used when a thread is created? How do they differ from those
used when a process is created?
16) Solaris, Windows XP , and Linux implement multiple locking mechanisms. Describe
the circumstances under which they use spin-locks, mutexes, semaphores, and
condition variables. In each case, explain why the mechanism is needed.
17) Explain the concept of transaction atomicity.
// PROGRAM 1
#include <stdio.h>
#include “thread.h”
Static void go(int n);
#define NTHREADS 10
static thread_t threads[NTHREADS];
int main (int argc, char **argv) {
int I;
int exitValue
for (i = 0; i < NTHREADS ; i++){
thread_create ( &(threads[i])), &go, i);
}
for (i=0; i<NTHREADS; i++){
exitValue=thread_join(threads[i]);
cout << “Thread returned with value “ << exitValue<< endl;}
}
cout << “Main Thread Done “ << endl;
return 0;
}
void go(int n) {
int threadNum = n;
cout << “Hello from thread “ << threadNum << endl;
thread_exit(100+n);
// not reached
}
18) For Program 1 the procedure go() has the parameter n and the local variable
threadNum. Are these variables per-tread or shared state? Where does the compiler
store these variables?
19) For program 1, the procedure main has local variables i and exitValue. Are these
variables per-tread or shared state? Where does the compiler store these variables?
20) Describe thread-local variables.
21) Describe 3 different models of interprocess communication. Include information on
the strengths and weaknesses.
22) What is the relationship between a guest operating system (like VMWare) and a host
operating system? What factors need to be considered in choosing the host operating
system?
23) Describe actions taken by the kernel to context switch between processes.
// PROGRAM 2
#include <stdio.h>
#include “unistd.h”
int main () {
/* fork a child process */
fork();
/* fork another child process */
fork();
/* fork another child process */
fork();
return 0;
}
24) Including the initial parent process, how man processes are created by the Program 2.
25) Give an example of a situation in which ordinary pipes are more suitable than named
pipes and example of a situation in which named pipes are more suitable than
ordinary pipes.
26) Which of the following components of program state are shared across threads in a
multi-threaded process?
a) Register values
b) Heap memory
c) Global variables
d) Stack memory
27) The Fibonacci sequence is the series of numbers 0,1,1,2,3,5,8,… Formally, it can be
expressed:
fib0 =0
fib1 = 1
fib2 = fibn-1 + fibn-2
Write a multithreaded program that generates the Fibonacci sequence using the pthread
library. The program should work as follows: The user will enter on the command line
the number of Fibonacci number that the program is to generate. The program will then
create a separate thread that will generate the Fibonacci numbers, placing the sequence in
data that can be shared by the threads (an array is probably the most convenient data
structure) when the thread finishes execution, the parent thread will output the sequence
generated by the child thread. Because the parent thread cannot begin outputting the
Fibonacci sequence until the child thread finishes, this will require having the parent
thread wait for the child thread to finish.
a) If we let the parent thread access the Fibonnacci numbers as soon as they have
been computed by the child, rather than wait for the child to terminate, what
changes would be necessary to the program? Why?
28) What are the three requirements for the critical-section problem?
29) What is a race condition?
30) What is the meaning of a spinlock? Explain why spinlocks are not appropriate for
single-processor systems yet are often used in multiprocessor systems.
31) Explain why interrupt are not appropriate for implementing synchronization
primitives in multiprocessor systems.
Download