DRAFT

Homework 7: an inter-process messaging library

Modern operating systems provide several means of inter-process communication. In linux, these include signals, pipes, System V IPC queues, shared memory and semaphores, UNIX and Internet sockets, and mmap() shared memory.

In this homework, we build our own inter-process messaging library using some of these underlying mechanisms. Using the preprocessor, we write code that works whether or not various different underlying mechanisms are available on our current system. We also run performance tests to determine the efficiency of various alternatives.

The listing below describes the public API of our messaging library.

%CODE{ lang="c" }% /* allocates space for a new message. In some implementations, this will be a simple malloc(). In others, more efficient methods may be available. */ void *new_message(int size);

/* returns a mailbox descriptor, or -1 on failure / int open_mailbox(char mailbox_name);

/* closes our descriptor on the supplied mailbox */ void close_mailbox(int mailbox);

/* reliably delivers the provided message to all processes that have an open descriptor on this mailbox. non-blocking. / void send_msg(int mailbox, void msg);

/* blocks until a message is received. The return value is a pointer to the message - user must call free_message() on the returned pointer to avoid a memory leak. / void receive_msg(int mailbox);

/* frees a previously received message / void free_msg(void message); %ENDCODE%

The homework template contains an implementation of the above API using System V Message Queues. Message queues implement essentially the same semantics described above, making the implementation pretty straightforward. Your job is to provide the same service without using message queues.

Implementation using System V shared memory and semaphores

In this part, System V queues may no longer available. Surround your System V queue-specific code with #ifdef SYSTEM_V_QUEUES preprocessor directives, so that your program uses System V queues when compiled with gcc -DSYSTEM_V_QUEUES, but does not use the queues otherwise.

When System V queues are unavailable, implement the same functionality using System V shared memory and semaphores.

Implementation using mmap()

Now, it may happen that none of the System V calls are available. Use an #ifdef SYSTEM_V directive to make your code use System V calls when available, but otherwise fall back on mmap() and the pthread library to implement the same functionality.

Implementation using the file system and flock()

Finally, mmap() may not be available either. use an #ifdef MMAP directive, and if mmap() is not available, fall back on using the file system for communication. Use flock() and signals ( kill()) for process synchronization, and read and write the contents of files for message passing.

Edit | Attach | Print version | History: r7 | r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r3 - 2011-03-01 - 01:02:09 - Main.jakob
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF