Q1 Shell Programming

  1. Write down the regular expression for a line that contains a single dollar amount only, such as $200
  2. The program compress will take a file and compact it to something smaller, to save space. Given a file as argument, it will compress it and rename it by adding a suffix .Z For example, compress file1 will compress file1 to file1.Z

    Write a bash shell script that will compress all the ordinary files in the current directory and in all of its subdirectories. The script should not attempt to compress files that have already been compressed i.e. those that end in .Z should not be compressed again.

Q2 Standard C

  1. Write a program in ANSI C that takes one command line argument, which is a string. The program is to print the string reversed. For example, if the program is called reverse then reverse abcde should print edcba (The program should use appropriate error reporting.)

  2. Write a function in ANSI C that will read an integer from standard input, a blank space, and then that number of characters. The function is to return the characters in a dynamically allocated string. (It should return appropriate error values.)

Q3 Systems Programming

  1. Write a program in C isdir that takes one command line argument. It should have an exit code of 0 if the argument is a directory, or other values if it is not. Hint: use stat()

  2. Write a program in C to count how many processes it can create. It should repeatedly create new process till it fails. Then it should print the number of processes created and exit.

Q4 File System

  1. When a process attempts to delete a file, the Operating System must ensure that the process has delete access to that file.
    1. Using the Unix directory and inode structure, explain how Unix can determine if the file /student/os/file1 can be deleted by a process with a user id of 20 and a group id of 40.

    2. Using the MSDOS FAT table structure, explain how MSDOS can determine if the file c:\windows\win386.swp can be removed by del.

  2. The Unix file system often has block size of 4k bytes. Ordinary text files have sizes typically in the range 1k - 16k. List some advantages and disadvantages if the block size was changed to 16k.

Q5 Memory and Process Management

  1. A set of processes are going to execute on a single CPU. They are Process Arrival time Expected CPU time 1 0 14 2 3 12 3 5 7 4 7 4 5 19 7 Determine the sequence of execution for each of the following CPU scheduling algorithms
    1. Shortest Job Next
    2. Round Robin, quantum size=4.
    Assume that there is no time lost during context switching.
    To answer, draw and fill in a table similar to the following: Time on Time off Process number Finished?
  2. Given a heap memory management scheme with the following free list: Free element Size in kb 1 100 2 500 3 200 4 300 5 600 The following process requests will be received in order: Process number Size in kb 1 212 2 417 3 112 4 426 Show the memory is allocated using the memory allocation schemes
    1. First Fit
    2. Best Fit

Q6 Remote Procedure Call

  1. In assignment 4, a file is fetched across the network if and only if it is not in the local cache. However, the source file may have changed so that the cache contains an old, out of date, copy. Discuss what changes need to be made to the RPC calls of assignment 4, and what (if any) additional RPC calls need to be added to ensure cache consistency: if the file is not in the cache then fetch_sound() else if the cache file is out of date then fetch_sound()
  2. Recursive data structures can easily be sent by RPC if they can be linearised. For example, a linear list

    can be sent as a b c d NULL and a binary tree can be sent in prefix order

    as a b d NULL NULL NULL c NULL NULL Give two examples of data structures that cannot be sent by this method.

Q7 Devices and IPC

  1. The keyboard device sends values to the device driver which depend on the keys, and on whether they are pressed or released. For example, Key<a>Down is a different value to Key<a>Up.

    The device driver will "autorepeat" keys if a key is pressed for long enough. Explain how it can do this. Explain whether or not it should autorepeat every key.

  2. Unix pipes have a default buffer size of 4k bytes. This can be altered, though, to say have a buffer size of 1 byte (unbuffered). Explain what consequences this would have for a typical pipeline such as ls | wc Are there any situations where an unbuffered pipeline would be useful?

Creative Commons License Copyright © Jan Newmarch under the terms of the Creative Commons Attribution 2.1 Australia License.