Free Essay

Comp3511 Hw1 Solution

In: Computers and Technology

Submitted By fatcheung09
Words 1136
Pages 5
Fall 2011 COMP 3511 Homework Assignment #1 Solution
Handout Date: Sept. 22, 2011 Due Date: Oct. 6, 2011
Name: ______________ ID: ___________________ E-Mail: _____________ COMP 3511 L __ Please read the following instructions carefully before answering the questions:  You should finish the homework assignment individually.  There are a total of 4 questions.  When you write your answers, please try to be precise and concise.  Fill in your name, student ID, email and Section number at the top of each page. Submissions without this information will be discarded.  Please fill in your answers in the space provided, or you can type your answers in a Word file.  Homework Collection: the hardcopy is required and the homework is collected at the collection box (#6, #7) or in class.
(22 points) Please answer the following question in 2-3 sentences 1) (8 points) What is the benefit of Direct Memory Access (DMA)? Is interrupt still needed when a DMA is used? Can DMA operations possibly interfere with CPU operations?


Answer: This frees up the CPU during I/O operation, so the CPU can be better used; Or to improve the CPU utilization (3 points). Interrupt is still needed when the DMA operation is completed in order to inform the CPU (2 points). If a DMA and CPU access memory at the same time, it can interfere with each other (3 points). 2) (4 points) Why is it necessary to separate user mode and kernel mode?

Answer: This provides some level of protection so that user programs can only run in user mode, with limited access to resources. 3) (6 points) Can you name three benefits of using virtual machine?

Answer: Software emulation of an abstract machine, programming simplicity, fault isolation (e.g., easy debugging as errors cannot crash the whole machine), protection and portability (e.g., Java across many platforms).

4) (4 points) Please name one benefit and one disadvantage using a Micro-kernel approach?

Answer: Benefits: this results in a smaller kernel which can be more easily ported from one hardware platform to another, or makes it easier to extend OS, new services do not require changes to the kernel. Or this also makes it more reliable and secure, since most services are running in user mode, not in kernel mode. Disadvantages: this adds overhead for system calls or suffer from performance degradation.


(20 points) Fork(). (1) (10 points) You have executed the following C program: main () { int pid; pid = fork (); if (pid) printf ("Parent runs\n"); else printf(“Child runs\n”); } What are the possible outputs, assuming the fork succeeded? Answer: Child runs Parent runs Or Parent runs Child runs (2) (10 points) You have executed the following C program: main() { int pid; int x = 0; pid = fork (); if (pid) { x = x + 1; printf ("The value of x in Parent is %d\n", x);

} else { x = x + 1; printf ("The value of x in Child is %d\n", x); } } Please show all possible outputs, assuming the fork succeeded. Answer: The value of x in Parent is 1 The value of x in Child is 1 or The value of x in Child is 1 The value of x in Parent is 1


(26 points) Process 1) (4 points) There are two states in a process, new and terminated. What is the use of them?

Answer: Allocating and de-allocating resources 2) (8 points) What are the 4 steps in creating a process?

Answer: construct a new PCB, set up new pages table for address space or simply set up memory space, copy data from parent process, copy I/O status. 3) (4 points) Can we determine the state of a process by the queues that it is associated with at a given time? Briefly justify your answer with an example.

Answer: Yes, for instance, a process in ready state must be placed on the ready queue. 4) (5 points) Why can not a process switch from waiting state to running state directly?

Answer: The CPU could be busy, it must go through ready state waiting to be scheduled to run 5) (5 points) with only one thread is referred as a heavy-weight process, why is there no concurrency within the execution of such a process?

Answer: Since there is only one “thread” of execution and instructions can only be executed sequentially. 4. (32 points) Thread 1) (8 points) What are the two components of program states that are shared by all threads within a process? What are the two components that are dedicated to each thread?

Answer: The threads of a multithreaded process share heap memory and global variables. Each thread has its separate set of register values and a separate stack. 2) (4 points) A multi-thread process and multiple processes can both provide concurrency, what is the major benefit of using a multi-thread process?

Answer: Threads within a single process shares code and data, the context switch between threads is much simpler 3) (8 points) What resources are used when a thread is created? How do they differ from those used when a process is created?

Answer: Creating either a user or kernel thread involves allocating a small data structure to hold a register set, stack, and priority. (4 points) Because a thread is smaller than a process, thread creation typically uses fewer resources than process creation Creating a process requires allocating a process control block (PCB), a rather large data structure. The PCB includes a memory map, list of open files, and environment variables. (4 points) 4) (12 points) What are the four states of Nachos threads, and briefly explain them [Hint: NACHOS Info under Thread]

READY The thread is eligible to use the CPU (e.g, it's on the ready list), but another thread happens to be running. When the scheduler selects a thread for execution, it removes it from the ready list and changes its state from READY to RUNNING. Only threads in the READY state should be found on the ready list.




The thread is currently running. Only one thread can be in the RUNNING state at a time. In Nachos, the global variable currentThread always points to the currently running thread. The thread is blocked waiting for some external event; it cannot execute until that event takes place. Specifically, the thread has put itself to sleep via Thread::Sleep(). It may be waiting on a condition variable, semaphore, etc. By definition, a blocked thread does not reside on the ready list. The thread exists, but has no stack yet. This state is a temporary state used during thread creation. The Thread constructor creates a thread, whereas Thread::Fork() actually turns the thread into one that the CPU can execute (e.g., by placing it on the ready list).

Similar Documents