#includeConsider: the following questions, also from the UNIX-hater's Web page: ``Without using anything but the calculator hanging off your belt, your VI quick reference card, and the LCD alarm chronograph mechanical pencil in your plastic pocket reinforce-omatic, describe in minute detail the output of this program. Expound in depth on the cultural and historical traditions behind every race condition involved, including insightful commentary on the personality quirks and religious practices of the parties responsible for each kernel bug you refer to in your explanation. Make sure to mention every operating system release in which your comments apply. Be concise and to the point. You may not blame it on the compiler. For extra credit, replace the fork() with vfork().''main() { printf("%d\n", foo() + (foo()<<1) + (foo()<<2) + (foo()<<3) ); } foo() { return(fork() ? 1 : 0); }
Hint: Consider violating the rules and compiling and running this code. From one run to the next, it produces wildly different outputs!
Consider a system with a paged address space, where the operating system treats the virtual address translation map of each process as a capability list. Without loss of security, could the system turn over a capability for a page, as a bit pattern, to a user process?
For example, consider implementing the function getcap(va) that returns a safely protected bit pattern representing the capability for the page at virtual address va in the caller's address space, and putcap(va,cap) that takes a bit pattern cap and installs the corresponding page in the caller's virtual address space at va.
Finally, given that secure implementations of getcap and putcap are possible, what is the effect on the rest of the system of prividing them to users?
Consider the problem of implementing locking in a distributed file system. Logically, a file lock is a semaphore associated with a file. When the file is locked, other users attempting to lock the file are blocked. When the file is later unlocked, one of the users blocked on that file is unblocked.
Typically, semaphores offer the operations P(sem) and V(sem), and a timer service might be exposed to the user as a service delay(t,sem) that signals the indicated semaphore after the indicated time interval has passed.
Consider the problem of implementing a timed wait. What is wrong with the following implementation:
timed_wait(sem,t) begin delay(t,sem) P(sem) endCan you fix the problem using the primitives provided? Can you fix it using multiple threads?