10B11CI511 Operating Systems Assignment 2
- Write a C program using fork system call for an automatic attendance system. In the system every student can mark their presence by showing their id cards (student id is scanned from the card as input for the program). After getting the students id the system checks in its database whether the student is registered in the course. If the student is registered the system marks present on the current day. Also the system checks if the attendance of the students is below 70% (including current day’s attendance), in which case the system generates a warning message. The classroom has 3 id scanners, ie. 3 students can mark their presence simultaneously.
- Write a multithreaded program using Java Threads for a retail store counter. At the counter a list is presented. The list can have 2 possible entries:
- An item (id-price pair). All such list entries are added to create a final bill amount presented to the customer.
- The customer then pays an amount to the cashier at the counter. If the amount is not the exact bill amount then the cashier puts the remaining amount in a buffer which is handled by another counter called the ‘change counter’.
- At the change counter 1 amount is read at a time and the change amount is returned in the minimum possible currency. (use standard Indian currencies in use presently.)
- A request item (item id). In case a store does not have the exact size or color etc. available for an item, a customer can put in a request for the same. For such a request, database of every sister store is scanned to check if the item is available in any other store and an appropriate message is given to the customer.
Note: A separate thread handles every such request.
Use function boolean isAvailable(int itemId); to check for the availability of a requested item.
Q.3. Write a multithreaded program using pthreads API for synchronous updation of a document. A common document (.txt) can be read by many users simultaneously.
- The system maintains a ‘last_update_time’ value for the document.
- Every user reading the document maintains an ‘open_time’ ie the time of opening the document for reading. The reader also periodically checks the ‘last_update_time’. If the reader finds that the ‘last_update_time’ is greater than the ‘open_time’, then the reader closes the file and reopens it.
The system also maintains an ‘under_updation’ flag.
Whenever a reader wishes to start modification of the file, he changes the ‘under_updation’ flag value to 1 (otherwise 0). And opens the file for writing. After completion of updation the flag value is changed back to 0 and the
‘last_update_time’ value is changed to the current time.
Note: if the ‘under_updation’ flag is set to 1 then no new user can start the updation unless the flag value goes back to 0.