EEL 358 - Operating Systems
Fall 2006
Indian Institute of Technology Delhi, New Delhi



Assignment 2

Process and Signals - A Dual Game Simulation

The objective of this assignment is to let you gain some hands on experience in Unix process creation and communication. You have to simulate a shooting game with N players and a moderator. This will also make you familiar with key signalling and concurrent program design.

 

Consider following scenario

¡@

A moderator and N players;

 

The moderator decides which player fights whom;

Only two players fight each other at a time;

(1) The moderator creates N players.

 

(2) All the created players are waiting for opponent information in the beginning.

 

(3) The moderator decides the opponents and informs them to start fighting by sending the opponent information.

 

(4) The opponents shoot at each other at some random time after they receive the opponent information.

 

(5) The player who gets shot first, informs the moderator before dying.

 

(6) The player alive waits for the moderator to send the next opponent information.

 

(7) The game proceeds in the same manner with all the players until only one player remains (the winner).

 

In effect, this is a tournament organized by the moderator;

  Instructions

(1) Your job is to implement the above scenario as an interaction between processes.

(2) Initially, the moderator creates players. Here, it gets the number of players from the user.

(3) The opponent information content (sent by the moderator to the players at the start of the fight) is to be decided by you.

(4) Set a reasonable random time before the player shoots. A maximum of 5 to 10 seconds would be fine.

(5) Make sure that the game proceeds like a tournament.

¡@

Implementation

            POSIX compliant C threads Library

Hints

(1) The moderator is the parent process that creates the child processes (players);

 

(2) Sending opponent information to players ® IPC;

 

(3) Shooting another player ® signal from one process to another;

 

(4) Dying ® process being killed;

 

(5) N can be even or odd;

Sample Instruction and Output

¡@

Enter the number of players (N):

¡@

4

¡@

Player 1 with PID 3216 created.

Player 2 with PID 3217 created.

Player 3 with PID 3218 created.

Player 4 with PID 3219 created.

¡@

Parent message: player 1 and 2 to fight.

¡@

Player 1 message: I have been shot.

¡@

Parent message: player 1 dead.

¡@

Parent message: player 3 and 4 to fight.

¡@

Player 3 message: I have been shot.

¡@

Parent message: player 3 dead.

¡@

Parent message: player 2 and 4 to fight.

¡@

Player 4 message: I have been shot.

¡@

Parent message: player 4 dead.

¡@

Parent message: Player 2 is the winner.

Make sure you distinguish messages from parent and child processes in the output.


Points Distribution  [Maximum 100]

1. Creation of child processes as specified in the problem ® 10%

2. Sending the opponent information to the child, i.e., message passing. ® 50%

3. Shooting and informing parent before dying ® 40%

4. Clarity, Formatting and General Layout ® Up to -10% if not followed
5. Originality ® Both copier and originator gets ZERO
6. Late Policy
® 20% reduction, allows ONLY one day delay.

Submission

Please submit a tar file on-line containing the following:

The tar file can be uploaded in the assignment # 2 using this link. Please make sure that you upload the assignment only once. In case of multiple submission ONLY first submission will be used for grading.

Deadline

The submission deadline for the assignment # 2 is 9th September 2006 [23:59 Hrs].

Questions

If you have any further questions relating to this assignment, you may contact the TA,  S.Karthikeyan.