Operating Systems
Exam 1
Name:________________________________ 27 February 2002
(20 minutes, 21 points) Booting. Assume that I place a newly formatted floppy disk with no files on it into the floppy disk drive of one of the computers in Williams 308 (which has been configured with both Linux and Windows) and turn it on. Assume also that BIOS is configured in the standard boot order (floppy first).
Explain in detail what happens (including what BIOS does). Why wont BIOS boot into Windows?
If I take the disk out (when requested to) and hit return what does BIOS do? Explain in detail how BIOS knows which partition to use, where the partition information is kept and how it is accessed, and how BIOS starts the boot process. You do not have to describe how the Linux kernel boots.
If I wanted to run a new daemon (say a web server) in the background in Linux and I wanted this daemon to run when the machine was booted up, which process would be most likely used to start the daemon? Why?
(20 minutes, 21 points) System Components and services.
Assume that you wanted to create a virus that would take over Linux. Your idea is to take advantage of the fact that a process operates in kernel mode when it makes a trap (i.e., a system call). In fact, a trap is implemented by a stub procedure that operates in user mode. You plan to take advantage of this fact to change either the mode bit or the address contained in the interrupt vector. Explain why this is not possible in Linux. Be sure to address all of the hardware protections.
Consider the fork( ) system call. Would this be a slow or fast interrupt? Why? If it were a slow interrupt, what would be done in the upper half and what would be done in the lower half? Why?
Consider the Write(fd, letters, letterSize) system call where the variable fd is a file descriptor to a file on the HD, letters is a string (char pointer) and letterSize is the size of the character string in bytes. What system components (as defined in Silberschatz chapter 3) would be involved in this call? Why?
3. (40 minutes, 28 points) System Calls. Write a program (in C) called getInfo that displays a prompt and waits for the user to enter a name. When the user enters the name and presses return you program should
a. read the name and
b. Create two new processes. The new processes must use the executable files userInfo-1, and userInfo-2. You must pass the name that you read in to the second process (but not the first), via the command line.
c. Display a prompt after all the new processes have terminated.
You must also provide the body of userInfo-1 and userInfo-2. These programs must run in the background and do the following:
UserInfo-1 must save information about jobs that the user is running into the file userInfo. You must add to the file, do not overwrite it. You must use ps and grep in your solution and your program must make grep take its stdin from pss stdout using pipes. You can use the whoami command to find out who the user is:
whoami
barr
UserInfo-2 must get the terminal information for the user who is currently logged on in this terminal (use the w command) and send it back to the original process (the original getInfo process that is) and that process must print the terminal info out to its stdout (you cant just fork off w in the child!). To simplify this program, assume that the name passed in via the command line argument is the account name.
4. (40 minutes, 30 points) Threads and message passing. Consider the producer-consumer solution in Java as given in the figures 5.11, 5.12, and 5.13 of the Silberschatz book. The solution also uses the MessageQueue class similar to the one given in figure 4.12. This solution is an unbounded, non-blocking solution. Change this solution to be a blocking (both send and receive) bounded capacity solution (capacity is 128 characters). You must use an array of characters in your modified MessageQueue. You can modify any of the four figures below to achieve your solution. You may not use any busy-waiting (i.e., loops) in your solution (i.e., you must block anyone that tries to send/receive when the queue is full/empty), though you may use loops in other places in your code. Note that you may have more than one consumer, but you dont have to synchronize between consumers (well get to that in a later chapter). No threads may be created in the MessageQueue class. You may use threads in the class.
import java.util.*;
public class MessageQueue
{
public MessageQueue(){
queue = new Vector();
}
// This implements a nonblocking send
public void send(Object item){
queue.addElement(item);
}
// This implements a nonblocking receive
public Object receive(){
Object item;
if (queue.size() == 0)
return null;
else{
item = queue.firstElement();
queue.removeElementAt(0);
return item;
}
}
private vector queue;
}
figure 4.12
public class Server {
public Server() {
MessageQueue mailBox = new MessageQueue();
Producer producerThread = new Producer(mailBox);
Consumer consumerThread = new Consumer(mailBox);
producerThread.start();
consumerThread.start();
}
public static void main(String args[]) {
Server server = new Server();
}
}
figure 5.11
class Producer extends Thread {
public Producer(MessageQueue m) {
mbox = m;
} public void run() {
while (true) {
// produce an item & enter it into the buffer
Date message = new Date( );
mbox.send(message);
}
}
private MessageQueue mbox;
}
figure 5.12
class Consumer extends Thread {
public Consumer(MessageQueue m) {
mbox = m;
} public void run() {
while (true) {
Date message = (Date) mbox.receive();
if (message != null)
// consume the message
}
}
private MessageQueue mbox;
}
figure 5.13