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.
  1. Not feasible: too many characters.
  2. Not feasible: too many characters.
  3. Feasible if the child prints first.
  4. Feasible if the parent prints first.
  5. Not feasible: not enough 1's
  6. Not feasible: not enough 1's
  7. Feasible if the child prints first and the parent interrupts the child before it prints its \n.
  8. 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:


CPU scheduling


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:
  1. P1: flag[1]=want_in.
  2. P1: j=0.
  3. P1: while succeeds because 0!=1.
  4. P1: if succeeds because flag[0]==idle.
  5. P1: j=1.
  6. P1: while fails because 1==1.
  7. P0: flag[0]=want_in.
  8. P0: j=0.
  9. P0: while fails because 0==0.
  10. P0: flag[0]=in_cs.
  11. P1: flag[1]=in_cs.
  12. P0: turn=0.
  13. P1: turn=1.
  14. P0: enters its critical section.
  15. P1: enters its critical section.

Deadlocks

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

  2. The system is safe. Here is a safe sequence and its derivation, shown in terms of the Work Vector.

    1. Work=(1,5,2,0). P0 can finish.
    2. Work=(1,5,3,2). P2 can finish.
    3. Work=(2,8,8,6). P1 can finish.
    4. Work=(3,8,8,6). P3 can finish.
    5. Work=(3,14,11,8). P4 can finish.

    The safe sequence is <P0,P2,P1,P3,P4>.

  3. 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
    R1 R2 R3 R4
    1 1 0 0

    Here's our search for a safe sequence.

    1. Work=(1,1,0,0). P0 can finish.
    2. Work=(1,1,1,2). P2 can finish.
    3. Work=(2,4,6,6). P1 can finish.
    4. Work=(3,8,8,6). P3 can finish.
    5. 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

  1. The size of a frame is 21=2 bytes because d is 1 bit long.
  2. The maximum number of segments a process can have is 22=4 because the segment number is 2 bits long.
  3. The maximum size of a segment is 22=4 bytes because the segment offset is 2 bits long.
  4. The maximum number of page tables a process can have is 23=8 because p1 is 3 bits long.
  5. The maximum number of entries that a page table can contain is 22=4 because p2 is 2 bits long.
  6. 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.
  7. 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.
  8. 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.
  9. 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:

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: 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:

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:
  1. 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.

  2. Austin switches to domain D1.

  3. Austin uses the copy right (*) to give domain D2 read access to the password file.

  4. Austin returns to his office at Sun Microsystems, Inc., where he writes a new game applet that he posts on his web site.

  5. Austin calls John and invites him to try out the new game.

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

  7. Austin receives the password file, from which he extracts LuAnn's password after spending a few hours to locate LuAnn's entry.

  8. Austin logs into the computer system using LuAnn's credentials and mails himself the budget file.

© 2004 Apostolos Lerios