Q1 Shell programming

  1. Write a shell script that takes one argument n. The script should write to standard output the value of n! (factorial n). This may be calculated using the formula 0! = 1 n! = n * (n-1)!
  2. Write a shell script that takes one argument file and copies the file standard output. Each line of output should be prefixed by its line number. For example, if the file contains a line or two of text then the output should be 1 a line 2 or two 3 of text



Q2 Standard C

  1. Write a C function that takes a string as parameter. The function should return a new string as value, where the new string is a copy of the old string with all leading spaces removed. For example, if the parameter is the string " some leading blanks" the function should return a new string "some leading blanks"

  2. Write a program in C that will take three command line arguments n op m where n and m are integers and op is one of the characters '+', '*' or '-'. The program should evaluate the expression and write the result to standard output.

    Hint: the function int atoi(char *) takes a string as parameter which it treats as the string representation of an integer, converts it to the integer and returns the value.









Q3 Systems programming

  1. Write a Unix program to open, read and close the current directory `.' using the system calls opendir, readdir, closedir (see the attached manual pages). The program should print the names of all the files in the current directory.

  2. Write a C program that runs with one command line parameter command. The program should execute the command and print a message saying how long it took to run.

    Hint: run the command as a separate process, while the parent waits for it and times it using the function long clock(void).




Q4 File System

  1. An existing file can have extra bytes appended to the end of it, leaving the existing contents unaltered. Discus how this can be done using
    1. The MSDOS file system.
    2. The Unix file system.

  2. Many computer viruses add their own code to existing files, changing their length. A simple way of detecting this is to compare file lengths before and after. Discuss the advantages and disadvantages of this, in no more than one page.



Q5 Memory management

  1. The memory of a system is 128 blocks and is organised using the buddy system. Intitially all memory is free. Requests are received of obtain 6 blocks obtain 10 blocks obtain 16 blocks obtain 8 blocks Show the state of memory after each request.

  2. In a virtual memory system, describe in less than one page how a virtual address reference is translated into a physical address.






Q6 Network

  1. A program is written that uses a procedure call char *finger(char *name) that returns a string of information about a name. This is to be made into a remote procedure call, where the remote server only handles this one function. Write a specification for the remote procedure call as a `.x' file that may be used by rpcgen to generate client and server stubs.

  2. Describe what can go wrong when writing blocks of a file using a remote procedure call across a network using
    1. ``At least once'' semantics i.e. repeat the procedure if it fails.
    2. ``At most once'' semantics i.e. do not repeat the procedure even if its fails.

Q7 IPC and devices

  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 a Unix terminal driver is in ``cooked'' mode, typing control-C will send an interrupt signal (SIGINT) to the reading process. Discuss how the device driver does this.