General Assignment guidelines
- Changes will be highlighted in
green
- Important notices will be
highlighted in yellow
- Assignments have to be strictly submitted according to guidelines. (will
be put up later)
- Assignments can be done in groups of two. lone wolves will be given some
extra credit.
Assignment on Interprocess Communication
Application
- Simulate journey of n cars traveling from Delhi to Agra.
- Assume that cars do not need to co-ordinate with each other (ignore
collision).
- Speeds of each car should vary as a pseudo random process: i.e. 1 sec
period the car will move forward a distance d(i) where d(i) is average_speed
+- random_noise to take into account potholes in the way.
- There are 5 filling stations/rest areas along the way. A car will randomly
choose to stop at a filling station/rest area and stop for a random amount of
time (but at least 10 seconds) and no more than 3 minutes. The cars start with
different capacities of fuel tank. Ensure that the cars will definitely stop
at a filling station if they don’t have enough fuel to reach the next filling
station. Again you can choose how much fuel you take on at a station.
- Display the positions, average speed and fuel status at the current
position of the cars.
- On keyboard input you should be able to reposition the cars.
- At the end, report the time in which the cars have completed the journey
Implementation
Framework of the program
- There will be two types of processes. Use fork() to create these
processes.
- Control process : One control process should be able to communicate with
the car processes. It will display the position and fuel status of the cars.
It should be able to accept keyboard input and should be able to reposition
the cars.
- Car process : There will be n number of processes for cars. They will
maintain speed, position, fuel status of the car and any other car specific
variables.
- InterProcess communication : Implement using each of the following IPC
primitives
- Pipes
- FIFO files
- Message Passing
- pthreads (the pthread package is not required to be downloaded. It is
built in to glibc). Note in case of pthreads you will not use the fork
- Programming Style:
- You should organize your code so that things are modular. You should
separate out declarations/prototypes into header files.
- You should make separate files for, the display/keyboard routines, the
car and control processes and one file each for each of the possible IPC
choices.
- Use a makefile to define how to make each of the possible targets
(carrace_pipes, carrace_fifo, carrace_mpc and carrace_pthreads) by suitable
compilation, linking and preprocessor directives.
- When programming application with different types of IPC (pipes, FIFO
files and message passing) only file for interprocess communication routines
should change. Other files should remain same. i.e. during compilation of
different applications, different IPC files should be used. (define
appropriate wrapper procedures so your main code need not change. You can
use the #ifdef preprocessor directive to selectively compile the relevant
code.)
- There should be no warnings at the time of compilation.
- Use ncurses to show different cars in different colours
- Background Reading
- Man pages for signal, alarm, umask, sigprocmask, gettimeofday, wait,
execve, fork, pipe, open, ipc, clone, msgctl, msgsnd, msgrcv, rand, srand48
- Unix Network Programming by W. Richard Stevens
- The
Linux Programmer's Guide
- linux pthreads
tutorial. Do not download the package for pthreads. It is built in to
glibc.
- ncurses for the display.( http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/,
http://web.cs.mun.ca/~rod/ncurses/ncurses.html
)
- man pages for make to learn how to prepare a Makefile.
You have to code using the framework
of the files provided below.
.c .h files and a sample Makefile are
now available.
Download
Last
date for submission:
Submission
with the pipes IPC primitive: Aug, 17 2003
Submission with all four options: Aug 22 2003