|
Alan Kaminsky
|
|
•
|
|
Department of Computer Science
|
|
•
|
|
Rochester Institute of Technology
|
|
•
|
|
4486 +
2220 =
6706
|
|
Home Page
|
|
Operating Systems I
|
|
•
|
|
4003-440-02
|
|
•
|
|
Winter Quarter 2012
|
|
Course Page
|
4003-440-02 Operating Systems I
Selected Exercises
Prof. Alan Kaminsky -- Winter Quarter 2012
Rochester Institute of Technology -- Department of Computer Science
Module 1. OS Structures
Module 2. Process Management
Module 3. Thread Programming
Module 4. Thread Coordination
Module 5. Concurrent Design Issues
Module 6. Process Programming
Module 7. CPU Scheduling
Module 8. Memory Management
Module 9. Memory Allocation
Module 10. File Systems and Disks
Module 11. Parallel and Distributed Systems
Module 1. OS Structures
Required reading
Exercises
-
A computer has a CPU, one level of cache memory, and a main memory.
The cache size is 1 megabyte
(1 megabyte = 220 bytes).
The cache is organized into cache lines of 32 bytes.
It takes 10 nanoseconds
(1 nanosecond = 10-9 seconds)
to transfer one byte of data
from the cache.
The main memory size is 256 megabytes.
It takes 100 nanoseconds
to transfer one byte of data
from the main memory.
The computer executes a 2-megabyte program
that contains absolutely no branch instructions,
just straight-line code.
Furthermore, the program uses only the CPU registers
and does not read or write any data in memory.
When the program starts, the cache is empty.
-
What is the cache hit ratio for this program?
-
How much time does it take to transfer
all the program instructions
from memory to the CPU?
-
Suppose the cache memory is eliminated
and the CPU is connected directly to the main memory.
Now how much time does it take to transfer
all the program instructions
from memory to the CPU?
-
A cache memory is supposed to speed up program execution.
Did it in this example?
If not, why not?
-
Every job in a certain computer system
executes as follows.
The job does computations with no I/O for 100 microseconds
(1 microsecond = 10-6 seconds).
The job then does an I/O operation
and must wait 1 millisecond
(1 millisecond = 10-3 seconds)
for the I/O to complete before proceeding.
The job does 1,000 iterations of this computation-I/O cycle,
then it stops.
-
The computer's operating system
does not support multiprogramming.
How long does it take to run one job? two jobs? five jobs?
(All jobs enter the system at the same time.
Ignore any overhead apart from the job execution time.)
-
The computer's operating system
supports multiprogramming.
How long does it take to run one job? two jobs? five jobs?
(All jobs enter the system at the same time.
Ignore any overhead apart from the job execution time.)
-
In the multiprogrammed operating system,
how many jobs are needed
to ensure the CPU is never idle
waiting for I/O to finish?
-
Explain why multiprogramming is A Good Thing.
-
In a certain computer
it takes 500 nanoseconds (1 nanosecond = 10-9 seconds)
to do a hardware context switch
in response to an interrupt
or to return from an interrupt.
The computer's timer triggers an interrupt
100 times a second.
The operating system's timer interrupt handler routine
takes 20 microseconds
(1 microsecond = 10-6 seconds)
to execute.
What fraction of the time
does the system spend dealing with timer interrupts?
Solutions
(password required)
Module 2. Process Management
Required reading
Exercises
-
Silberschatz, Chapter 3, Exercise 3.9.
-
Silberschatz, Chapter 3, Exercise 3.10.
-
Silberschatz, Chapter 3, Exercise 3.13.
-
A command interpreter program or shell,
such as csh or bash,
runs each command in its own separate process.
Normally, after the user types a command,
the command prompt will not be displayed
until after the command has run.
However, if the user ends a command with an ampersand (&),
the command prompt will be displayed immediately.
On a Unix system,
which system calls does the shell have to do
to run a command?
What does the shell have to do differently
if the user ends a command with &?
-
Every process in a certain computer system
executes as follows.
The process does computations with no I/O for 100 microseconds
(1 microsecond = 10-6 seconds).
The process then does an I/O operation
and must wait 1 millisecond
(1 millisecond = 10-3 seconds)
for the I/O to complete before proceeding.
Each process repeats this computation-I/O cycle forever.
There are 20 processes in the system.
The operating system's scheduler works as follows.
When the scheduler needs to run a different process,
the scheduler takes the process
at the front of the ready queue.
When a process becomes ready to execute,
the scheduler places the process
at the end of the ready queue.
After the system has run for a while,
how many processes will be in the ready queue?
In the I/O wait queue?
What fraction of the time will a process spend
in each of the process states?
(All processes start at the same time.
Ignore any overhead apart from the process execution time.)
-
Silberschatz, Chapter 4, Exercise 4.9.
-
Silberschatz, Chapter 4, Exercise 4.10.
-
Silberschatz, Chapter 4, Exercise 4.11.
-
Silberschatz, Chapter 4, Exercise 4.13.
-
A certain program uses a thread pool.
When the program tells the thread pool to run a task in a separate thread,
the thread pool reuses an existing idle thread if possible,
otherwise the thread pool creates and uses a new thread.
Once a thread has finished running a task,
the thread goes back into the thread pool
as an idle thread.
The program runs 50 tasks in sequence.
Each task starts 50 milliseconds
(1 millisecond = 10-3 seconds)
after the previous task started.
Each task finishes 1 second after it starts.
After all the tasks have finished,
how many idle threads will be sitting in the thread pool?
(Ignore any overhead apart from the task execution time.)
Solutions
(password required)
Module 3. Thread Programming
Required reading
Exercises
In Java, a thread can be programmed
either as a subclass of class Thread
or as a class that implements interface Runnable.
Give reasons one might prefer to use each technique.
-
A Java program has four threads.
Each thread prints the message
"Hello, world from thread <i>!"
on the standard output,
where "<i>"
is replaced by the thread number (1-4).
Write three different versions of this program,
using three different techniques
to create and run the threads.
-
Professor K assigned the previous program for course credit.
The professor's goal is to automate grading the student's projects
by doing a diff between the program's output
and the correct output (stored in a file).
If there are no differences,
the project gets a 100,
otherwise the project gets a 0.
Will Professor K be able to achieve this goal?
Explain why or why not.
Solutions
(password required)
Module 4. Thread Coordination
Required reading
Exercises
-
Silberschatz, Chapter 6, Practice Exercise 6.2.
-
Silberschatz, Chapter 6, Exercise 6.17.
-
Silberschatz, Chapter 6, Exercise 6.18.
-
Silberschatz, Chapter 6, Exercise 6.25.
-
Silberschatz, Chapter 6, Exercise 6.28. (Write a pseudocode monitor.)
-
Silberschatz, Chapter 6, Exercise 6.29. (Write a pseudocode monitor.)
-
Silberschatz, Chapter 6, Exercise 6.32. (Write a pseudocode monitor.)
-
Silberschatz, Chapter 6, Programming Problem 6.39. (Write a pseudocode program.)
-
The Java Virtual Machine guarantees
that reading the value of an int variable
is an atomic operation
and assigning a value to an int variable
is an atomic operation.
Consider this class:
public class SharedInteger
{
private int value;
public synchronized int get()
{
return value;
}
public synchronized void set
(int value)
{
this.value = value;
}
public synchronized void add
(int value)
{
this.value = this.value + value;
}
}
In order for a SharedInteger object
to be used by multiple threads,
is it necessary for every one of the above methods
to be synchronized?
Which methods have to be synchronized
and which methods need not be synchronized?
Explain why.
What would be the advantage of having certain methods unsynchronized
(if that is possible)?
-
Curiously, the Java Virtual Machine
does not guarantee
that reading or assigning a long or double variable
is an atomic operation.
Why is that?
(Hint:
Think about the size of such a variable
compared to the word size of the typical CPU.)
Solutions
(password required)
Module 5. Concurrent Design Issues
Required reading
Exercises
-
Silberschatz, Chapter 7, Practice Exercise 7.3.
-
Silberschatz, Chapter 7, Exercise 7.10.
-
Silberschatz, Chapter 7, Exercise 7.11.
-
Silberschatz, Chapter 7, Exercise 7.15.
-
Silberschatz, Chapter 7, Exercise 7.17.
-
Silberschatz, Chapter 7, Exercise 7.20.
-
Silberschatz, Chapter 7, Exercise 7.21.
Questions 8-9.
An old-fashioned data center has four computers
sharing six magnetic tape drives.
The data center is running four applications concurrently,
one application on each computer.
Each application requires exclusive use of certain tape drives.
Each application acquires its tape drives
in the order given below.
-
Application A -- Tape drives 1, 3, 4
-
Application B -- Tape drives 4, 2
-
Application C -- Tape drives 3, 5
-
Application D -- Tape drives 6, 2, 1
If a tape drive is not available,
the application waits until the tape drive is available,
then the application acquires the tape drive and proceeds.
Once the application has acquired all its tape drives,
the application performs a computation using the data stored on the tapes,
then the application releases all its tape drives.
-
Is it possible for the data center to get into a deadlock?
If so, give a sequence of events that leads to a deadlock.
If not, explain why a deadlock is impossible.
-
If the data center can get into a deadlock,
describe how would you change the applications to make deadlock impossible.
If the data center cannot get into a deadlock,
describe how would you change the applications to make a deadlock possible.
Solutions
(password required)
Module 6. Process Programming
Required reading
Exercises
-
The user types the following command to the shell:
cat file | tr -s -c '[:alpha:]' '[\n*]' | tr '[:upper:]' '[:lower:]' | sort -u | wc -l
The shell runs each individual command in its own process.
How many calls to pipe(), fork(), and exec()
must occur?
-
Here's one way the shell could run the commands.
The shell forks a process,
and the new process execs the first command (cat).
The shell forks another process,
and the new process execs the second command (tr).
And so on, until all the commands are running.
Draw a diagram showing each process including the shell,
with an arrow pointing from each process to its parent.
-
In Question 2,
what has to happen
to prevent the shell from going on to the next user command
until all the commands have finished?
-
Here's another way the shell could run the commands.
The shell forks a process,
and the new process execs the first command (cat).
The shell forks another process,
and the new process execs a new shell
with a command line argument
telling the new shell to run the rest of the user's command
except for cat.
And so on, until all the commands are running.
Draw a diagram showing each process including the shell,
with an arrow pointing from each process to its parent.
-
In Question 4,
what has to happen
to prevent the shell from going on to the next user command
until all the commands have finished?
-
If you were writing the shell program,
which approach would you use?
Explain why.
-
Describe what the command in Question 1 does.
Solutions
(password required)
Module 7. CPU Scheduling
Required reading
Exercises
-
Silberschatz, Chapter 5, Practice Exercise 5.1.
-
Silberschatz, Chapter 5, Practice Exercise 5.3.
-
Silberschatz, Chapter 5, Exercise 5.9.
-
Silberschatz, Chapter 5, Exercise 5.11.
-
Silberschatz, Chapter 5, Exercise 5.12.
-
Silberschatz, Chapter 5, Exercise 5.13.
-
Silberschatz, Chapter 5, Exercise 5.15.
-
Silberschatz, Chapter 5, Exercise 5.16.
-
Silberschatz, Chapter 5, Exercise 5.19.
-
Silberschatz, Chapter 5, Exercise 5.20.
-
Silberschatz, Chapter 5, Exercise 5.21.
Solutions
(password required)
Module 8. Memory Management
Required reading
Exercises
-
Silberschatz, Chapter 8, Practice Exercise 8.4.
-
Silberschatz, Chapter 8, Practice Exercise 8.6.
-
Silberschatz, Chapter 8, Exercise 8.11.
-
Silberschatz, Chapter 8, Exercise 8.12.
-
Silberschatz, Chapter 8, Exercise 8.14.
-
Silberschatz, Chapter 8, Exercise 8.15.
-
Silberschatz, Chapter 8, Exercise 8.16.
-
Silberschatz, Chapter 8, Exercise 8.17.
-
Silberschatz, Chapter 8, Exercise 8.18.
-
Silberschatz, Chapter 8, Exercise 8.19.
-
Silberschatz, Chapter 8, Exercise 8.20.
-
Silberschatz, Chapter 8, Exercise 8.21.
-
Silberschatz, Chapter 8, Exercise 8.23.
-
Silberschatz, Chapter 8, Exercise 8.24.
-
Silberschatz, Chapter 8, Exercise 8.25.
-
A certain computer uses paging.
Addresses are 32 bits long,
and each page contains 1,024 addresses.
The page table contains the following entries
(all numbers are in decimal):
| Page # |
|
Page Frame # |
| 0 |
|
22 |
| 1 |
|
7 |
| 2 |
|
32 |
| 3 |
|
17 |
| 4 |
|
51 |
| 5 |
|
53 |
| 6 |
|
41 |
| 7 |
|
57 |
| . . . |
|
. . . |
What is the physical address corresponding
to each of the following logical addresses?
Give the addresses in decimal.
-
1107
-
906
-
4870
-
7191
-
6601
What is the logical address corresponding
to each of the following physical addresses?
Give the addresses in decimal.
-
33214
-
22824
-
8020
-
52609
-
42490
-
Silberschatz, Chapter 9, Practice Exercise 9.7.
-
Silberschatz, Chapter 9, Practice Exercise 9.8.
-
Silberschatz, Chapter 9, Exercise 9.15.
-
Silberschatz, Chapter 9, Exercise 9.20.
-
Silberschatz, Chapter 9, Exercise 9.21.
-
Silberschatz, Chapter 9, Exercise 9.23.
-
Silberschatz, Chapter 9, Exercise 9.29.
-
Silberschatz, Chapter 9, Exercise 9.32.
-
Silberschatz, Chapter 9, Exercise 9.33.
-
Silberschatz, Chapter 9, Exercise 9.34.
-
Consider the sequence of page references in Figure 9.20 (page 389).
The operating system uses demand paged virtual memory
and allocates at most 4 page frames to each process.
Give the number of page faults and the page miss ratio
for each of the following page replacement algorithms.
Also state which page replacement algorithm
(other than OPT) gives the best performance.
-
OPT.
-
LRU.
-
FIFO.
-
Second chance.
Solutions
(password required)
Module 9. Memory Allocation
Required reading
Exercises
-
Silberschatz, Chapter 9, Exercise 9.36.
Solutions
(password required)
Module 10. File Systems and Disks
Required reading
Exercises
-
A computer uses the Linux ext2 filesystem
with 1,024-byte disk blocks.
For each of the following file sizes,
state how many disk blocks are needed for the file's contents,
state how many disk blocks are needed
to hold indirect pointers (not counting the inode),
and state the overhead fraction for the indirect pointers.
-
10,464 bytes.
-
98,765 bytes.
-
220,057,435 bytes.
-
Silberschatz, Chapter 12, Exercise 12.16.
-
Silberschatz, Chapter 12, Exercise 12.17.
-
Silberschatz, Chapter 12, Exercise 12.18.
-
Silberschatz, Chapter 12, Exercise 12.33.
-
Silberschatz, Chapter 12, Exercise 12.35.
Solutions
(password required)
Module 11. Parallel and Distributed Systems
Required reading
Exercises
-
You have made the following measurements
of running time T (msec)
versus number of processors K
for a certain parallel program
solving a problem with a fixed problem size N:
K T
1 14000
2 7560
3 5413
4 4340
-
What fraction of this program's total running time
must be performed sequentially?
-
What would the program's running time be for K = 5 processors?
-
What are the program's speedup and efficiency
for K = 1, 2, 3, 4, and 5 processors?
-
What is the maximum speedup you can expect from this program
as K increases while holding N fixed?
-
A weather prediction program
divides a three-dimensional region
of the Earth's surface and atmosphere
measuring 1 kilometer (width)
× 1 kilometer (length)
× 1 kilometer (height)
into a 1000×1000×1000 grid of cells,
each cell representing a cube 1 meter on a side.
The program simulates a time span of 24 hours;
the program divides this time span into 1440 time steps,
each time step representing 1 minute.
The program takes 1 hour to run on a single processor.
The program is now to be run on a 16-processor parallel computer
while still calculating the same three-dimensional region
for the same total (simulated) time span.
-
Under ideal conditions,
what would the grid cell size, time step size,
and total running time be
if strong scaling is used?
-
Under ideal conditions,
what would the grid cell size, time step size,
and total running time be
if weak scaling is used?
-
Which would give a more accurate weather prediction,
strong scaling or weak scaling?
Explain.
-
The above weather prediction program
(with the original grid)
is run on an SMP parallel computer
with 16×109 bytes of memory
available to store the grid.
Each grid cell requires 8 bytes of data.
-
How much memory does the program require
to store the whole grid?
-
You want to increase the number of cells in the grid
from 1000×1000×1000
to N×N×N.
How large can the grid dimension N become
on this SMP parallel computer?
-
You want to increase the number of cells in the grid
from 1000×1000×1000
to 4000×4000×4000,
and run the program on a cluster parallel computer
in which each node
has 16×109 bytes of memory
available to store the grid.
How many nodes must there be in the cluster?
-
A certain GPU parallel program
with a certain input data set
is run on a previous-generation NVIDIA Tesla C2075 accelerator
with 448 cores.
The identical program with the identical input data set
is then run
on a next-generation NVIDIA Tesla K20 accelerator
with 2496 cores.
-
What kind of scaling is this? Explain.
-
The K20 cores are 3 times faster
than the C2075 cores.
All else being equal,
what would the program's speedup be
running on the K20
as compared to running on the C2075?
-
The DES block cipher uses a 56-bit key.
A brute force attack on DES
requires performing the encryption function
256 times.
The world's fastest supercomputer,
the Sequoia computer
at the Lawrence Livermore National Laboratory,
Livermore, CA, USA,
has 1572864 cores.
Assume that one core can perform the encryption function
in one microsecond (1×10−6 seconds).
Assume an ideal speedup.
How long will it take the Sequoia computer
to perform the brute force attack on DES?
-
Twelve nodes have joined a peer-to-peer system that
uses the Chord distributed hash table.
The system uses hash values in the range 0-127.
The node names and the node identifier hash values are:
A B C D E F G H I J K L
103 80 100 20 17 5 72 71 121 70 35 50
-
Draw a picture of the Chord ring,
showing each node A through L
in its proper position on the ring.
-
Give the finger table for node L.
-
A key X is added to the distributed hash table.
The hash of X is 122.
On which node (A through L) will X be stored?
-
A user tells node D to do a query for key X.
To which node(s) will the query be forwarded?
-
A very large database is split into chunks,
and the chunks are stored separately on the nodes of a cluster.
Each chunk has a numerical ID.
For purposes of integrity checking,
we want to compute the digest of the database
using the SHA-1 hash function.
The hash function takes an input of any size
and outputs a fixed-size 160-bit digest.
We want to compute the database's digest
using a tree hash:
The digest of each database chunk is computed;
these digests are all concatenated together,
in ascending order of the chunk IDs;
the digest of the concatenation is computed;
and that is the digest of the whole database.
We want to use map-reduce to compute the database digest.
-
Describe what the mapper input(s) are,
describe what the mapper computation does,
and describe what the mapper output(s) are.
-
Describe what the reducer input(s) are,
describe what the reducer computation does,
and describe what the reducer output(s) are.
-
Justify why we want to use map-reduce to compute the database digest.
Solutions
(password required)
|
Operating Systems I
|
|
•
|
|
4003-440-02
|
|
•
|
|
Winter Quarter 2012
|
|
Course Page
|
|
Alan Kaminsky
|
|
•
|
|
Department of Computer Science
|
|
•
|
|
Rochester Institute of Technology
|
|
•
|
|
4486 +
2220 =
6706
|
|
Home Page
|
Copyright © 2013 Alan Kaminsky.
All rights reserved.
Last updated 13-Feb-2013.
Please send comments to ark@cs.rit.edu.