File monitor A file is to be shared among different processes. The file can be a
ID: 3744239 • Letter: F
Question
File monitor
A file is to be shared among different processes. The file can be
accessed simultaneously by more than one process, up to a maximum
of 5 processes. In pseudo-code write a monitor to coordinate
access to the file. For example:
FileMonitor M;
int main() {
...
M.RequestAccess();
/* Access file: open, read, close, etc. */
M.FinishedAccess();
...
}
Monitor FileMonitor {
/* monitor variables here */
void RequestAccess() { /* Code here */ }
void FinishedAccess() { /* Code here */ }
}
The monitor pseudo-code needs to define monitor variables and the
monitor functions.
Notes
• This is pseudo-code and not meant to be compiled and run.
You will need to check the logic though.
• This is a monitor so mutual-exclusion is assured and does not
need to be incorporated in the code.
• Assume that the monitor uses Mesa condition variables.
• As a starting point study Figure 5.19 (ed. 8, Figure 6.20)
from the text book (Operating System Concepts, Silberschatz
et el.).
5
Explanation / Answer
Monitor FileMonitor {
/* monitor variables here */
int count = 0;
semaphore cond;//semaphore variable to lock
void RequestAccess() { /* Code here */
while(count >= 5){
cond.wait();
}
assert(count < 5);
count++;
}
void FinishedAccess() { /* Code here */
count--;
cond.notify();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.