OS Lab Assignment 4
Assignment 4
Implementing Publisher-Dispatcher-Subscriber System
Assignment
You are required to develop 3 types of programs:
- Publisher
Publisher program reads the messages from the user input stdin and writes them into a message queue. The input by the user can be assumed to be a ninteger always. There can be n number of publishers running in the system at a time.
- Dispatcher
Dispatcher process reads the messages from the message queue to which the publisher processes write. It then identifies the message and invokes the particular subscriber to that message.
For example, if the message received is 1, then it dispatches this event to the corresponding subscriber of that message, by sending a SIGALRM signal to that subscriber process.
- Subscriber
Subscriber is the process which handles a particular message. It registers itself with the dispatcher (by sending its process id to the dispatcher thru another message queue).
It overrides the SIGALRM signal handler to handle it (say print some message) and then sleeps (use sleep(some_very_big_int)).
Some important points to note
- There can be any number of publishers in the system.
- There is only one dispatcher.
- The number of subscribers can be assumed to be fixed (minimm of 3). Therefore the user input to the publisher can be 1, 2 or 3.
- The dispatcher when started, first waits for all the (3) subscribers to register with it (it receives the pids of the subscribers thru another message queue). Once all the (3) subscribers are registered, it proceeds to read the Publisher message queue and depending on the message it sends the SIGALRM to the registered process.
- It can be assumed that there is only one subscriber per one type of message.
-
When the registered message is enter the dispatcher identifies this process and sends it the SIGALRM signal.
- Upon receving the SIGALRM signal, the sleeping subscriber should print some message.
- The publisher, dispatcher and subscribers should be running in separate windows.
- Each subscriber should be run in a separate window.
- The tutorial material can be found here.
- Some material on message queues can be found here
- Some material on signals can be found here
Submission
Submit your .c (or any file) file using ~oslab/submit script as in: ~oslab/submit 4 myfile.c
submit script accepts assignment no. in its first argument. Any number of files may be
submitted through subsequent arguments.
You may submit any number of times before 6:00pm. Old files are overwritten in resubmission.
In case of any problem with submission, pls mail your assignments to subash@cse.iitb.ac.in
Deadline: 6:00pm