28.01.2015 Views

PDF format

PDF format

PDF format

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CS 1901473 Operating Systems; Exam 2; Saturday, May 15, 2004; 1 Hour<br />

Student Name (CAPITAL LETTERS): _______________________________________<br />

Student Number: __________________________________________<br />

Section: ___________________<br />

Problem 1(10 pts)<br />

Answer yes or no, or with a single term or short answer, as appropriate.<br />

a) Does the test-and-set instruction need to be a privileged instruction<br />

b) A resource allocation graph that has a cycle in it always/sometimes/never means<br />

that there is a deadlock<br />

c) What approach to dealing with deadlock does the Banker’s algorithm implement<br />

d) A system that meets the four deadlock conditions will always/sometimes/never<br />

result in deadlock<br />

.<br />

Problem 2 (10 pts)<br />

What is the advantage of using threads compared to processes (your answer should be<br />

short. VERY SHORT)<br />

Problem 3 LINUX (10 pts)<br />

a) write down the command needed to change the file permission to be as shown<br />

below:<br />

Filename: file1, Required file permission :_r_x r_ _r_ _ <br />

b) write down the command that will give you long listing for the content for your<br />

current directory<br />

c) write down the command that will show you the process tree available on your<br />

system<br />

d) If you have a process P1 hanged in the system, what is the name of the<br />

command used to terminate this process <br />

Page 1 of 4


Problem 4 (30 pts)<br />

a) (15 pts) Three processes share four resource units that can be reserved and<br />

released only one at a time. Each process acquires and releases resources over<br />

time but only needs a maximum of two resource units at any one time. Deadlock<br />

can not occur. Why<br />

b) (15 pts) Consider a system consisting of m resources of the same type, being<br />

shared by n processes. Resources can be requested and released by processes<br />

only 1 at a time. Show that the system is deadlock free if the following two<br />

conditions hold:<br />

(I) The max need for each process is between 1 and m resources.<br />

(II) The sum of all max needs is less than n + m.<br />

Problem 5 (15 pts)<br />

In lecture we said that, if the semaphore operations Wait and Signal are not executed<br />

atomically, then mutual exclusion may be violated. Assume that Wait and Signal are<br />

implemented as below:<br />

void Wait (Semaphore S) {<br />

while (S.count


Problem 6 (25 Points)<br />

Consider a system that has W workers and M managers that continuously enter and<br />

leave an office. Work can only be done in teams consisting of 1 manager and 2 workers<br />

in the office. The detailed requirements are:<br />

• Managers arrive to a FCFS queue, and workers arrive to their own FCFS queue.<br />

• When the manager at the front of the queue is ready, he/she picks the next two<br />

workers for his team and tells them to begin working. Then, the next manager<br />

can form his/her team in a similar manner.<br />

• Workers tell their manager when they are done working and leave immediately.<br />

• A manager does not leave until all team members have said they are leaving.<br />

• After work is completed, the team members leave for a random amount of time<br />

before re turning.<br />

a) Describe the synchronization for the manager process by writing the manager<br />

process in terms of the counting semaphore primitives Signal() and Wait() and<br />

the semaphore and variable declarations. Note: You do not need to give the<br />

worker process code; i.e., you can assume that the worker process is given.<br />

b) Describe the use of each semaphore and the general logic of the manager<br />

process. You can do that using comments in your code.<br />

HINT: (Note: You may use the following skeleton.)<br />

struct {<br />

int manager;<br />

int worker[2];<br />

int n=0;<br />

} newTeam;<br />

// shared<br />

// manager of new team<br />

// which workers are forming a new team<br />

// how many entries in worker[2]<br />

... semaphore definitions ...<br />

Page 3 of 4


process manager (i) {<br />

int myTeam[2];<br />

// who is on my team<br />

}<br />

do forever {<br />

... code ...<br />

}<br />

process worker (i) {<br />

... NOT NEEDED ...<br />

}<br />

Page 4 of 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!