Q1 Shell Programming

  1. Write a regular expression to match a string ending in .gif, where the letters ``gif'' can be in upper or lower-case, and the string takes up the whole of the line.
  2. Write a shell script that takes either zero or one command line argument. It should count the number of regular (ordinary) files in a directory and print the result to standard output. (The count need not include ``hidden'' files beginning with `.'.) The directory should be the command line argument, or if there is none it should be the current directory.


    Q2 Standard C/C++ Programming

    1. Write a C or C++ program which reads characters from standard input, checking that they are all alphabetic characters. The program should exit with a zero exit status if it reaches end of file on standard input and all charcters read are alphabetic. If it reads a non-alphabetic character it should cease reading and exit with a non-zero exit status.
    2. To generalise the mechanism for checking command line options, the following structure could be used:
        typedef struct option_t {
            int set;     /* boolean: option is set or unset */
            char option; /* the single char for the option */
            char *usage; /* string to print for help/usage messages */
        } option_t;
      
      Given an array of options
        #define NUM_OPTS 3
        option_t options[NUM_OPTS];
      
      1. Write a function to set the options `h', `v', `s' as in assignment two, with suitable set and usage values.
          void initialise_options(option_t options[])
          
      2. Given a possible option e.g. `h', write a function to take the option and the array
          int check_option(char opt, option_t options[], 
                           int num_opts)
          
        that will put the appropriate set field to true. The function should return true if it could find a matching option, or false otherwise.


        Q3 Systems Programming

        1. Write a program in C or C++ that uses opendir() etc to count the number of files (including directories) in the current directory. Do not include `.' and `..' if they exist. Print the final count to standard output.
        2. Write a function in C or C++ that takes a filename as parameter and returns the user identity uid (a positive integer) of the owner of the file. It should return a suitable error value if the information cannot be obtained. Hint: use stat() (see attached man page).

          Q4 Memory Allocation

          1. A 128-byte block is used for memory allocation using the buddy system. After a while, it looks like this, where the shaded blocks are allocated and the unshaded blocks are free:

            The blocks of memory are then freed in order:
            1. 8-byte block starting at 8
            2. 4-byte block starting at 4
            3. 8-byte block starting at 16
            4. 32-byte block starting at 64
            5. 16-byte block starting at 32
            6. 4-byte block starting at 0 After each of these, show the state of memory, and indicate when appropriate which blocks have been coalesced.
            7. A virtual memory paging scheme has a four page frame memory and an eight page virtual address space with 512 (01000 octal) byte pages. The following page table relates virtual pages to physical page frames for a process:
              Virtual       Page
               page         index
              -------------------
                0             3
                1             1
                2
                3
                4             2
                5
                6             0
                7
              
              What are the actual physical addresses of the following virtual addresses (in octal):
              1. 01000
              2. 00030
              3. 06100
              4. 05200 Explain briefly what happens if there is no physical address for a requested virtual address.

                Q5 File Systems

                  1. Using the Unix file system, assume that the inode of the current directory is known. Explain how to find the inode of the file ../file1 (if the file exists).
                  2. Using the MSDOS file system, assume that the location of the first block on disc of the current directory is known. Explain how to find the first block of the file ..\file1 (if the file exists).
                  3. Consider the following mechanism for adding a new data block to a file:
                        get a new block from the free list
                        write data to the block
                        update inode/FAT pointers
                        update size, last modified, etc fields
                    
                    If the system crashes somewhere during this (or is switched off, etc), discuss some of the ways in which the filesystem can become `inconsistent' i.e. have some erroneous values.


                    Q6 Processes

                    1. Two processes are running asynchronously. One process communicates to the other that it wishes the other process to start and stop execution. Discuss how this can be done using
                      1. Signals
                      2. A pipeline
                      3. Shared memory
                      4. When the mail program pine starts it creates a lock file and will not allow you to start another copy of the mailer till the lock is removed. When netscape starts it creates a lock file and if you try to start another one then it warns you about the lock.

                        How do they do this, and what is the purpose of it?