CSCI 4534 - Operating Systems
Final Answers
Processes
Feasible outputs are those where the parent prints 11\n
and the child prints 0\n
, though the two print operations
can be interleaved arbitrarily.
- Not feasible: too many characters.
- Not feasible: too many characters.
- Feasible if the child prints first.
- Feasible if the parent prints first.
- Not feasible: not enough 1's
- Not feasible: not enough 1's
- Feasible if the child prints first and the parent interrupts the
child before it prints its
\n
.
- Feasible if the parent prints first and the child interrupts the
parent before it prints its second
1
.
Threads
Java threads can be preeempted at any point during their
execution. This is because a Java program's instructions are in byte
code, which is executed by the JVM one instruction at a time. The JVM
may thus decide to implicity force the running thread to yield when it
receives any program instruction. By contrast, a C program using
Pthreads executes on the CPU directly, so there is no layer such as
the JVM to enforce yielding.
Green threads are pure user threads, so if one of them blocks, the
JVM's single kernel thread blocks on I/O. As a result, another green
thread cannot take over the CPU.
User-level threads can be mapped to kernel-level threads in three
ways:
- Many-to-one.
- + No kernel overhead (context-switching and kernel data
structures).
- One-to-one.
- + If one thread blocks, others can run.
- Many-to-many.
- + Most efficient as additional kernel threads are allocated as
needed (e.g. when a thread blocks).
CPU scheduling
- Below is the Gantt chart under SJF scheduling:
0........3
| 4........6
| 7........13
| 14........22
|
P1
| P3
| P2
| P4
|
The average response time is ((1-0)+(8-1)+(6-2)+(16-3))/4=6.25.
- The Gantt chart and the average response time under SRTF
scheduling are the same as for SJF scheduling.
- Below is the Gantt chart under RR scheduling with a quantum of 1:
0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
|
P1
| P2
| P3
| P4
| P1
| P2
| P3
| P4
| P1
| P2
| P3
| P4
| P1
| P2
| P4
| P2
| P4
| P2
| P4
| P2
| P4
| P4
| P4
|
The average response time is ((4-0)+(5-1)+(10-2)+(11-3))/4=6. Note
that a process issues its response after initialization is
complete. So, for example, a process that needs 1 unit to initialize
will issue its response at the beginning of its second slice:
the first slice was used up initializing the process.
- Below is the Gantt chart under RR scheduling with a quantum of 3:
0.....2
| 3.....5
| 6.....8
| 9.....11
| 12.....12
| 13.....15
| 16.....18
| 19.....19
| 20.....22
|
P1
| P2
| P3
| P4
| P1
| P2
| P4
| P2
| P4
|
The average response time is ((1-0)+(4-1)+(8-2)+(11-3))/4=4.5.
- They are irrelevant. The book refers to optimality under a
different measure, i.e. the average waiting time. Our measure is a
different one, so our results have no relevance to the book's
claim. The only conclusion we can draw is that SJF is not optimal if
our measure is the average response time.
- No it does not. We got a better average response time with a
quantum of 3 than with 1.
Process sychronization
The proposed solution to the critical section problem for n
processes is incorrect because it violates the mutual exclusion
requirement. Here is a counterexample, where n=2 and P0 and
P1 are the two participating processes:
- P1:
flag[1]=want_in
.
- P1:
j=0
.
- P1:
while
succeeds because 0!=1
.
- P1:
if
succeeds because flag[0]==idle
.
- P1:
j=1
.
- P1:
while
fails because 1==1
.
- P0:
flag[0]=want_in
.
- P0:
j=0
.
- P0:
while
fails because 0==0
.
- P0:
flag[0]=in_cs
.
- P1:
flag[1]=in_cs
.
- P0:
turn=0
.
- P1:
turn=1
.
- P0: enters its critical section.
- P1: enters its critical section.
Deadlocks
- Here are the contents of the Need matrix:
| R1
| R2
| R3
| R4
|
P0
| 0
| 0
| 0
| 0
|
P1
| 0
| 7
| 5
| 0
|
P2
| 1
| 0
| 0
| 2
|
P3
| 0
| 0
| 2
| 0
|
P4
| 0
| 6
| 4
| 2
|
- The system is safe. Here is a safe sequence and its derivation,
shown in terms of the Work Vector.
- Work=(1,5,2,0). P0 can finish.
- Work=(1,5,3,2). P2 can finish.
- Work=(2,8,8,6). P1 can finish.
- Work=(3,8,8,6). P3 can finish.
- Work=(3,14,11,8). P4 can finish.
The safe sequence is
<P0,P2,P1,P3,P4>.
- The resource instances are available, so we then check whether
this allocation would leave the system in a safe state. Here are the
matrices:
Allocation
| Need
| Available
|
| R1
| R2
| R3
| R4
|
P0
| 0
| 0
| 1
| 2
|
P1
| 1
| 4
| 2
| 0
|
P2
| 1
| 3
| 5
| 4
|
P3
| 0
| 6
| 3
| 2
|
P4
| 0
| 0
| 1
| 4
|
|
| R1
| R2
| R3
| R4
|
P0
| 0
| 0
| 0
| 0
|
P1
| 0
| 3
| 3
| 0
|
P2
| 1
| 0
| 0
| 2
|
P3
| 0
| 0
| 2
| 0
|
P4
| 0
| 6
| 4
| 2
|
|
|
Here's our search for a safe sequence.
- Work=(1,1,0,0). P0 can finish.
- Work=(1,1,1,2). P2 can finish.
- Work=(2,4,6,6). P1 can finish.
- Work=(3,8,8,6). P3 can finish.
- Work=(3,14,11,8). P4 can finish.
A safe sequence is
<P0,P2,P1,P3,P4>,
as before. The request is therefore granted immediately.
Memory management
- The size of a frame is 21=2 bytes because
d is 1 bit long.
- The maximum number of segments a process can have is
22=4 because the segment number is 2 bits long.
- The maximum size of a segment is 22=4 bytes because
the segment offset is 2 bits long.
- The maximum number of page tables a process can have is
23=8 because p1 is 3 bits long.
- The maximum number of entries that a page table can contain is
22=4 because p2 is 2 bits long.
- The maximum size of the address space of a process is 16 bytes
because a process can have at most 4 segments, each 4 bytes long.
- The maximum size of the address space of a process would be 64
bytes because the process can have 8 page tables, each with 4 pages,
and each page is 2 bytes long.
- The only reason we have a page directory is to accomodate small
processes without allocating a single large page table for each
process. Therefore, if processes always have an address space of
maximum size, we don't need the page directory and hence
p1 should be 0 bits long; in other words, we can
get rid of this part of a linear address altogether.
- In order for a process to have access to 16 bytes in memory, it
must be able to have 16/2=8 pages. This requires a page table with
23=8 entries, which means that p2 must
be 3 bits long.
Virtual memory
Assume:
- 2 frames.
- The circular queue pointer points to the first frame.
- The reference string is 1,2,1,3
SC
p/r
shows p
(the page) and r
(the reference bit).
String: 1 2 1 3
Frames: 1/1 1/1 1/1 3/1
2/1 2/1 2/0
Fault: y y n y
LRU
String: 1 2 1 3
Frames: 1 1 1 1
2 2 3
Fault: y y n y
File systems
These are the contents of the FAT:
Index
| Contents
|
0
| 6
|
1
| -1
|
2
| 8
|
3
| -2
|
4
| 3
|
5
| -1
|
6
| 4
|
7
| -2
|
8
| 7
|
9
| -1
|
RAID
The maximum capacity of the RAID system as a whole is:
- RAID 0: 4*128GB=512GB.
- RAID 1: 2*128GB=256GB.
- RAID 4: 3*128GB=384GB.
- RAID 5: 3*128GB=384GB.
- RAID 0+1: 2*128GB=256GB.
- RAID 1+0: 2*128GB=256GB.
There are
128GB/4KB=(128*230)/(4*210)=32*220=32M
blocks on each disk. The number of blocks that store parity
information under each of the following RAID levels are:
- RAID 0: 0. No parity is stored under RAID 0.
- RAID 4: 32M, which is one disk's worth.
- RAID 5: 32M, which is one disk's worth.
Security
Austin can indeed take a series of actions that will eventually lead
to him receiving a copy of Microsoft's budget; these actions are:
- Austin uses John's terminal to switch to domain
D3. Austin knows he can do this because he can see the
access matrix posted above John's terminal, and has the engineering
skill to understand it.
- Austin switches to domain D1.
- Austin uses the copy right (*) to give domain
D2 read access to the password file.
- Austin returns to his office at Sun Microsystems, Inc., where he
writes a new game applet that he posts on his web site.
- Austin calls John and invites him to try out the new game.
- John runs the new applet, which is indeed a game. But, in the
background, the applet contains a trojan horse. Since the applet runs
in domain D2, it can read the password file and send it
over the network to Austin.
- Austin receives the password file, from which he extracts LuAnn's
password after spending a few hours to locate LuAnn's entry.
- Austin logs into the computer system using LuAnn's credentials
and mails himself the budget file.
© 2004 Apostolos Lerios