<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

CS 471
Operating Systems


Spring 2011
Final Exam

Time 2 & 1/2 hours


Open Book & Notes

 

 

 

 Name:

 Unix Login:

 

All questions are of equal weights.

 

 


Question 1

 

Consider the following program:

Q1.c

#define N 3
pthread_mutex_t mymutex[N];

void main(int argc, char *argv[])
{
   int             i;
   for (i = 0; i < N; i++) {
        pthread_create(NULL, NULL, task, (void *) i);
        sleep(1);
   }
   pause();
}

void  *task(void *arg)
{
   int             myindex = (int) arg;
   printf("Starting task %d\n", myindex);
   pthread_mutex_lock(&mymutex[(myindex) % N]);
  
sleep(2);
   pthread_mutex_lock(&mymutex[(myindex + 1) % N]);
   printf("Doing my task %d\n", myindex);
   pthread_mutex_unlock(&mymutex[(myindex) % N]);
   pthread_mutex_unlock(&mymutex[(myindex + 1) % N]);
   printf("Ending task %d\n", myindex);
}

 

What is the print out of Q1?

â Answer:

 

 

 

 

 

 

 

A.  What is the print out Q1 if  we remove the statement: sleep(2);

â Answer:

 

 


 

 

Question 2

 

A.  Assume that memory addresses are 16 bits long and the virtual memory page size is 1024 bytes.

What is maximum number of pages?

â Answer:

 

 

 

 

 

B.   Fill in the number of page faults in the following matrix, assuming the following page reference string:

 

9  5  5   1   0    1    6   0   8    6   2  9

 

 Working set

             size

Page

Replacement Algorithm

1

3

7

Optimal

 

 

 

FIFO

 

 

 

LRU

 

 

 

LFU

 

 

 

MFU

 

 

 

 

 


 

Question 3

 

 

A.  Consider the following commands:

 

% cd /usr/bin

% ls -l passwd

-r-sr-sr-x   1 root  sys  27228 Aug 16  2007 passwd

% who am i

cs471w   pts/15       2011-04-16 15:05 (dhcp-154.cs.odu.edu)

% passwd

 

Who are the USER and the Real USER during the execution of passwd?

 

â Answer:

 

 

 

B.   Consider the following access matrix.

Is it possible for D4 to access the laser printer? Explain.

 

 

 

â Answer:

 


 

A.  Assume your published public key  is  <3,10> and your private key is <7,10>.

Someone sent you a cipher message C = 2 .

What is the value of the original message M  corresponding to C?

â Answer:

 


 

Question 4

 

A.  Consider the following program:

Q4.c

main(int argc, char *argv[])
{
     int             fd;
     char           *fname;
     fname = argv[1];
     if ((fd = open(fname, O_RDWR)) == -1) {
           printf("error openning: %s\n", fname);
           exit(-1);
     } else {

printf("opened %s\n", fname);
printf("fd is %d\n", fd);
exit(0);

     }
}


What is the output of the following statements?

% touch testfile

% Q4 testfile

 

 

 

% rm testfile

% Q4 testfile

 

 

 

B.   What is the output of the last 3 cat commands:

 

% rm testfile

% echo Wahab > testfile

% cp testfile f1

% ln testfile f2

% ln -s testfile f3

% rm testfile

 

% cat f1

% cat f2

% cat f3


 

Question 5

 

A.  Calculate the total head movement for servicing the following request Queue according to the specified disk I/O scheduling algorithms.

 

Request Queue (cylinder range 0-100):         80   30  10   20   60

Head pointer:  cylinder 40

 

Disk Scheduling Algorithm

FCFS

SSTF

C-LOOK

 

Total Head Movement

 

 

 

 

 

B.   Consider the following program:

 

Q5.c

main(int argc, char *argv[])
{

     char           *fname = argv[1];
     if (fork() == 0)
           ReadFunction(fname);
     else if (fork() == 0)
           WriteFunction(fname);
     else if (fork() == 0)
           WriteFunction(fname);

     else if (fork() == 0)
           ReadFunction(fname);
     else
           pause();
}
ReadFunction(char *file)
{
     int             fd;
     if ((fd = open(file, O_RDONLY)) < 0) {
           perror(file); exit(1);
     }
     printf("request read lock\n"); 
     read_lock(fd);
     printf("obtained read lock\n");
     printf("sleeping 20 seconeds while read locked ...\n");   
     sleep(20);
     unlock(fd);
     printf("sleeping 10 seconeds while not read locked ...\n");
     sleep(10);
     printf("Reader Exiting...\n");
}


 

WriteFunction(char *file)
{
     int             fd;
     if ((fd = open(file, O_WRONLY)) < 0) {
           perror(file); exit(1);
     }
     printf("request write lock\n");
     write_lock(fd);
     printf("obtained write lock\n");
     printf("sleeping 20 seconeds while write locked ...\n");
     sleep(20);
     unlock(fd);
     printf("sleeping 10 seconeds while not write locked ...\n");
     sleep(10);
     printf("Writer Exiting...\n");
}

What is the output  the following command:

 

% Q5 Q5.c