CS3013 Practice Final Exam

  1. Put the system calls in order for use in a typical shared-memory program:

    1. shm = shmat(id)
    2. strcat(shm)
    3. shmctl(id, IPC_RMID)
    4. shmdt(shm)
    5. id = shmget(KEY, SIZE, PERMS)

  2. Assume the following code is compiled and run:

      int n=0;  /* global variable */
      main() {
        n = n + 1;
        printf("n: %d\n", n);
      void doit(void) {
        int x=0;
        x = x + 1;
        printf("x: %d\n", x);
    Assume all system calls succeed.
    1. What are all the possible outputs from 1 of the processes?
    2. Assume the fork() call is changed to a spawn() call that creates an additional thread in the same process instead of a new process. Now, what are all the possible outputs from 1 of the processes?

  3. For the SOS SelectProcessToRun() sample below, show how you would modify it to support two processes. Assume each processor has a variable named p1 and p2 respectively. Use cli() and sti() (as in the Linux kernel) for any required synchronization.

      int SelectProcessToRun() {
        static int next_proc = MAX_PROCESSES;
        if (current_process > 0 
    	&& pd[current_process].slotAllocated
    	&& pd[current_process].state == READY
    	&& pd[current_process].timeLeft > 0)
          return current_process;
        for (int i=1; i < MAX_PROCESSES; i++) {
          if (next_proc >= MAX_PROCESSES)
    	next_proc = 1;
          if (pd[next_proc].slotAllocated && pd[next_proc].state == READY) {
    	pd[next_proc].timeLeft = TIME_QUANTUM;
    	pd[next_proc].state = RUNNING;
    	return next_proc;
        return -1;
  4. Fragmentation:

    1. What is external fragmentation? In what memory partitioning schemes (fixed, variable or paged) do we have it?
    2. What is internal fragmentation? In what memory partitioning schemes (fixed, variable or paged) do we have it?

  5. Consider the following page reference string:


    Assume pure demand paging so your first unique pages will all cost one fault each. Assume the process has a 4 frames at all times.

    1. How many page faults would occur for a Least Recently Used (LRU) replacement algorithm using 4 frames?
    2. How many page faults would occur for the best possible page replacement algorithm? Describe briefly how this algorithm works.

  6. Consider a demand-paging system with the following time-measured utilizations:

        CPU utilization:     99%
        Paging disk:         10%
        Other I/O devices:    8%

    Which (if any) of the following will (probably) decrease CPU utilization?

    1. Install a faster paging disk
    2. Install a bigger paging disk
    3. Increase the degree of multiprogramming
    4. Decrease the degree of multiprogramming
    5. Install more memory
    6. Install a faster CPU
    7. Upgrade to a high-bandwidth file system

  7. Suppose that a 32-bit virtual address is broken up into three fields: a, b, and c. The first two, a and b, are used for a two-level page table system. The third field, c, is the offset. If a, b, c are 4, 2, 4, respectively. How large is each page? How many pages can be in a logical address space?

  8. What is the role of the device independent layer of a device driver?

Return to the CS3013 Home Page