Semaphore&Message Passing
Semaphore&Message Passing
Assignment # 2
Operating Systems
Due Date: October 11, 2011
where Index is the logical number for consumer process, assigned internally by your code, and varies between 0 and n 1. The child process will be execed by the command equivalent to the shell comand palin xx key where xx is the index number of the child process and key is the key to shared memory. We want to have three log les: one containing admin data such as the attempts to get into critical section, the second containing all palindroms, and the third containing all non-palindromes. Use the same specs for child processes as from previous assignment. The multiple processes compete to get exclusive access to the le to write into, participating in the race condition. They also compete to nd the next string to be processed. You will use the monitor you wrote to gain access to these resources such that only one process can see/modify the number or gain access to the les to write into those. In addition, the main process should print a message when an interrupt signal (^C) is received. Make sure that all the children/grandchildren are killed by main process when this happens, and all the shared memory is deallocated. The grandchildren kill themselves upon receiving interrupt signal but print a message on stderr to indicate that they are dying because of an interrupt, along with the identication information. Make sure that the processes handle multiple interrupts correctly. As a precaution, add this feature only after your program is well debugged.
Implementation
The code for and child processes should be compiled separately and the executables be called master and palin. Other points to remember: You are required to use fork, exec (or one of its variants), wait, and exit to manage multiple processes. Use shmctl suite of calls for shared memory allocation. Also make sure that you do not have more than twenty processes in the system at any time. This should be easy because you have static child processes to do the work in this project. What to handin Handin an electronic copy of all the sources, README, Makele(s), and results. Create your programs in a directory called username.2 where username is your login name on hoare. Once you are done with everything, remove the executables and object les, and issue the following commands: % cd % ~sanjiv/bin/handin cs4760 2 Do not forget Makefile (with sux rules), RCS, and README for the assignment. If you do not use RCS, you will lose 10 points. Omission of a Makefile (with sux rules) will result in a loss of another 10 points, while README will cost you 5 points. Print messages when a process waits for and acquires a semaphore into the log le.