Assignment 4

Operating Systems and Computer Structures G2

Assignment 4

Due date

This assignment is due by 5pm, 28 October at the end of week 15.

Introduction

This is an exercise in distributed processing using a remote procedure call.

This assignment requires you to access a service that is only available on a remote computer. Access to this service is by using a remote procedure call. The service is a ``fortune cookie'', that gives you (sometimes) amusing quotes. For example,

    If you think education is expensive, try ignorance.
                -- Derek Bok, president of Harvard
or
    A long-forgotten loved one will appear soon.
    Buy the negatives at any price.

Specification

You should write two C programs that take no parameters. The two programs will be indentical except that the first will use local procedure calls only, while the second will use a remote procedure call.

The first program must have a local procedure call

char *get_cookie(void)
This will just return a string (e.g. "dummy cookie").

The second program should replace this with a remote procedure call

char *get_cookie(void)
(see later).

Both programs should read from standard input, and accept the following one-letter commands, one per line:

When the quit command is received, the program should exit (exit code 0). When a new cookie is fetched, it should be printed and also added to a list of cookies previously fetched. The program should maintain a list of upto 10 cookies, discarding the oldest ones when more than 10 cookies are fetched. When a digit 0 is entered, the progam should print the most recently fetched cookie, when a 1 is entered the cookie before that should be printed, etc.

Remote call

The remote procedure will run on machine pandonia.canberra.edu.au. The remote call will return a null-terminated string no longer than 1024 bytes (including the '\0' terminator). This should make use of the remote procedure specification file ~ostutes/rpc/rcookie.x. Use the program rpcgen to generate the client side interface file rcookie_clnt.c and the header file rcookie.h

The directory ~ostutes/rpc also contains a sample get_cookie that can run on the server side, and just return a dummy cookie. You can use this during development where the server is set to localhost instead of pandonia. When this is working, change the server to pandonia.

Errors

If a digit is entered for which there is no cookie, a simple message saying this should be printed. If a command other than 'q', 'g' or '0'..'9' is entered, an error mesage should be printed. In each case, the program should continue processing.

Submission

Do not hand in a copy of the program on paper. Instead, hand it in electronically using the command give. This command runs with two parameters. The first parameter should be the assignment name and the second should be the name of the file containing your C program.

For the first program the assignment name is ``a4stub''. e.g.

    give a4stub cookie_stub.c
For the second program the assignment name is ``a4''. e.g.
    give a4 cookie_client.c

You may run give any number of times. Each time you run give it replaces any earlier submission of the assignment.

Submit the C source code for your assignment, not the executable