CS3013 Homework A

Due date: Monday, October 3rd

You must turn in your homework in written form by the beginning of class on the date it is due.

The questions are based on material presented in class and reading material from the text.

Give brief answers to the following questions:

  1. Suppose your OS does not yet have semaphores but the computer system does have the Test_and_Set() function. Assuming only a single semaphore is needed, implement the functions wait(void) and signal(void) using the Test_and_Set() function as a user-level function. You may use any shared boolean variables needed for your solution (i.e. one or more "lock" variables). What are the potential drawbacks, if any, of this semaphore implementation?

  2. Following is an implementation of a producer-consumer mailbox that can contain one message at a time. In the below implementation, the consumer does not wait if the producer has not yet made a message. Using only semaphores, make the consumer print the message once if and only if there is a message in the mailbox created by the producer.

            struct message mbox;   /* shared */
            producer() {
              struct message my_msg;
              while(1) {
                create_msg(&my_msg);     /* create my message */
    	    put_msg(mbox, my_msg);   /* put my message in the mbox */
            consumer() {
              struct message my_msg;
              while(1) {
                get_msg(&my_msg, mbox);  /* get message from the mbox */
    	    print_msg(my_msg);       /* print my message */

  3. Consider an OS with the below process control block (PCB). Write another data structure that contains exactly enough information needed to support threads (a thread control block, or TCB). A thread should be able to access the containing process from the TCB.

             struct PCB {
                 int     pid               /* Process ID */
                 int     state;            /* ready, running or blocked */
                 int     timeLeft;         /* time left since last time slide */
                 struct  SaveArea sa;      /* hardware state to save */
                 struct  InOut  *pIO;      /* pointer to IO descriptors */
                 struct  Heap   *pHeap;    /* pointer to heap */
                 struct  Stack  *pStack;   /* pointer to stack */

  4. Briefly explain the difference between internal and external fragmentation. In particular, explain why paging has no external fragmentation. What kind of fragmentation do you have with variable sized partitions?

  5. Consider a logical address space of 32 pages of 2048 bytes (words) each, mapped onto a physical memory of 64 frames.

    1. How many bits are there (minimum) in the logical address?
    2. How many bits are there (minimum) in the physical address?
    3. How many entries are there in the page table?
    4. How large, in bits, is the page table?

  6. Consider a paging system with the page table stored in memory.

    1. If the time to access physical memory is 90 nanoseconds, how long will be a paged memory reference?
    2. If we add associative registers (a TLB), and 95% of the memory references are in the associative registers, what is the the effective memory access time?
  7. Assuming a concurrent client and server for a distributed shell project. Arrange the following system calls in the right order for both a client and a server: accept(), connect(), listen(), , close() bind(), socket(), fork(), exec(), send(), recv(), dup2(), puts(). Indicate needed loops with a while(){} statement. You may use calls more than once, as needed.

Return to the CS3013 Home Page

Send all questions to the cs3013-ta at cs.wpi.edu mailing list.