Q: What are the four main functions of a memory manager?
A: 1. Keep track of which parts of memory are in use.
A: 2. Allocate memory to processes when they require it.
A: 3. Protect memory against unauthorized accesses.
A: 4. Simulate the appearance of a bigger main memory by moving data automatically between main memory and disk.

Q: What is meant by a dirty page?
A: An unreferenced page that was modified when the clock hand reaches it, it is written out to disk (clearing the Modified bit) but is not made a candidate for replacement.

Q: How does memory compaction work?
A: Moves all processes into a single contiguous area at one end of memory, leaving an unused area at the other end. [Alternatively, one could create an unused area in the middle.]

Q: What are the three tricks used to resolve absolute addresses?
A: 1. Position Independent Code [PIC]
A: 2. Relocation
A: 3. Base and Limit Registers

Q: Why would an overlay be used?
A: Used as some programs require more main memory than the computer has.

Q: How can the problem of TLB during context switching be avoided?
A: Clear the TLB at the context switch, or include a Process ID in every TLB entry, and check these on every reference.

Q: What is swap space?
A: Memory images kept on disk.

Q: What is meant by SWAPPING IN a process?
A: Having its image brought into memory from disk.

Q: What are the problems that arise with absolute addresses in terms of swapping?
A: When a program is loaded into memory at different locations, the absolute addresses will not work without software or hardware tricks.

Q: What is the advantage of Base-Limit Registers in comparison to PIC and Relocation?
A: Guarantees Security:
A: 1. Compares every program-generated address with the limit register and generates an exception if the limit is exceeded.
A: 2. Allows the base and limit registers to be modified only in KERNEL mode.

Q: Where is the MMU located?
A: MMU is located between the CPU and the BUS.

Q: What does the physical address space of a machine contain?
A: One address for each memory cell.

Q: Why does FIFO have poor performance?
A: 1. Because it disregards the principle of locality.
A: 2. Pays no attention to page usage.

Q: What is a downfall of memory compaction?
A: It is very expensive, it can freeze all other activities for several seconds.

Q: What is the method of using Base and Limit registers?
A: Relies on extra hardware, when loading memory image of a process, the OS sets the base register to point to the start of the image. 
A: Hardware adds the value in the base register to every address generated by program before accessing memory.

Q: What does MMU stand for?
A: Memory Management Unit.

Q: What is compaction time dependant on? Explain where a dilemma could occur?
A: 1. More Memory [More Time]
A: 2. Better CPU/BUS [Less Time]
A: Dilemma: Better CPUs come with More Memory.

Q: What is meant by SWAPPING OUT a process?
A: Moving its memory to disk, to free up memory.

Q: Where is the 'area of memory' occupied by a process recorded?
A: In the Process Table.

Q: What is an overlay?
A: Divisions in a program is made into overlays. At any time only one overlay is in memory, when the program needs code or data in another overlay, the program commands the current overlay to be swapped out and the required overlay to be swapped in.

Q: What is a downfall of LFU?
A: If a page was once heavily referenced, LFU will leave it in memory even after it has outlived its usefulness.

Q: What is the aim of memory compaction?
A: To create a single unused area of memory.

Q: What maps virtual pages onto physical pages?
A: MMU

Q: What is your recommendation in the use of the silicon area on which TLBs are implemented?
A: Instead of using silicon space to handle misses [miss handler], it should go to making a larger TLB to reduce the miss rate.

Q: Give an example of a primitive MMU.
A: B-L registers and the hardware that uses them.

Q: What is a free list?
A: A list whose elements point to the unused blocks in the system.

Q: What is internal fragmentation?
A: Unused/Wasted space inside a region allocated to a process.

Q: What happens if a process exceeds the LIMIT in B-L resolution?
A: Generates an exception.

Q: What are the four classifications of pages in NRU algorithms [in order]?
A: 0: not Referenced, not Modified [Lowest Priority]
A: 1: not Referenced, Modified
A: 2: Referenced, not Modified
A: 3: Referenced, Modified [Highest Priority]

Q: What generates PIC?
A: Compiler.

Q: What is external fragmentation?
A: Fragmentation outside of allocated area.

Q: On memory access plots, what is the distribution of temporal locality?
A: Narrow horizontal slice, whose width is a single instruction or item of data, will show clumps in accesses.

Q: What is the method of relocation?
A: The compiler separates absolute addresses and passes this info to the OS, which can then adjust the contents of those words and registers when it loads the program at a new location.

Q: When does external fragmentation occur?
A: When a large process exits and is swapped out and is replaced by a smaller process.

Q: What are two page table structures?
A: 1. Split table organization
A: 2. Directory organization

Q: Why are BL, PIC, and Relocation limited in comparison to virtual memory?
A: Because they require the entire program code and data to be in main memory when the program is running.

Q: What is a trick that a process can use to bypass BL limit restrictions? How is the system safe from this trick?
A: A program could try to use negative addresses [which will always appear to be less than the LIMIT] to evade a comparison.
A: This will not work because addresses are unsigned.

Q: Why is a memory map used?
A: A memory manager uses a memory map to know for each word of memory, whether the word is free and if not, which process it belongs to.

Q: What is the problem with PIC?
A: References to variables now require an extra addition, which slows the program down.

Q: What is a page frame?
A: A physical page.

Q: What is the purpose of a physical page?
A: To hold a virtual page.

Q: Where do pages start out when a process is run?
A: Pages in virtual address space all start out on disk.

Q: A virtual address has two parts, what are they?
A: 1. Virtual Page Number
A: 2. Offset

Q: How is 'page size' determined?
A: 2^(Number of bits in offset)

Q: In a paged system, how is an address viewed?
A: Always viewed as:
A: page_number * page_size + offset

Q: Why are page sizes powers of two? Why is this necessary?
A: Division is trivial if a page_size is a power of two.
A: This is necessary, as the decomposition of an address into a page_number and offset requires division.

Q: What is a page map?
A: A mapping of virtual address to physical addresses and vice- versa.

Q: Where is the information required to do mapping contained?
A: Page Table.

Q: What is a page table?
A: Table recording the mapping of virtual addresses to physical addresses.

Q: What is the relation between page tables and processes?
A: Each process has its own virtual address space, and thus its own page table.

Q: What is contained within a page table entry?
A: 1. Physical Page Number
A: 2. Valid Bit
A: 3. Modified Bit
A: 4 Permission bits [Read/Write/Execute]

Q: What does the number of page table entries depend on?
A: #(Page Table Entries) = #(Virtual Pages)
A: One Entry per virtual page number

Q: What does the valid bit represent?
A: Whether the virtual page is in main memory or not.

Q: On many systems, if the page is not in memory, what happens to the physical page number field?
A: The physical page number field contains the address of the page on disk.

Q: Describe the steps involved in a page table operation?
A: 1. Virtual page # is found on page table.
A: 2. Valid and Permission bits are checked.
A: 3. Corresponding physical page# is located,
A: 4. Physical page offset = Virtual page offset.

Q: What checks the valid bit and permissions of a requested memory access in a PTE?
A: The MMU performs these checks.

Q: What is a page fault?
A: An EXCEPTION, in which the valid bit is 0 OR permissions do not permit.

Q: What throws a page_fault exception?
A: MMU

Q: During a check of a PTE using the MMU, what happens if permissions permit and valid bit = 1, and the request is a WRITE?
A: The modified bit in the PTE is set to 1.

Q: When is the modified bit = 1?
A: When a request in a PTE is valid, with correct permissions and request was a WRITE.

Q: What handles page faults?
A: Page Fault Handler.

Q: What does the page fault handler do if a page fault is caused due to permissions being violated?
A: Terminates the process.

Q: What are the steps involved in page fault handling, given that the page was not valid, but permissions are acceptable?
A: 1. Suspend process
A: 2. Free up a page frame if necessary
A: 3. Load required virtual page from swap space into a free page frame.
A: 4. Cause MMU to map Virtual page onto Physical page
A: 5. Restart process at the same instruction.

Q: What is meant by the term idempotent?
A: This means that an instruction should do no harm if executed TWICE.

Q: After a page fault, the OS reissues faulting instruction. What can go wrong?
A: If the instruction is non-idempotent, it will cause harm when executed again.

Q: How does the machine deal with non-idempotent instructions? When is this not a practical solution?
A: The hardware delays any non-idempotent actions until no possibility of page fault remains.
A: This is not practical for long running instructions.

Q: What kinds of machines do NOT handle virtual memory?
A: Machines that have instructions that are neither restartable or continuable.

Q: What does TLB stand for?
A: Translation Lookaside Buffer

Q: What is purpose of TLB?
A: The TLB serves as a cache for recently accessed PTEs.

Q: Where is TLB located?
A: In the MMU.

Q: Why are TLBs now included in most paged computers?
A: Because without TLB, each memory reference by a program in a paging system, would require two memory accesses: One to access the PTE, and one to access the data.

Q: Describe two-level page table structure?
A: A page table directory is always in memory when the process runs; its entries point to page table fragments. The fragments may be in memory or on disk, or not exist at all if that region of address space is not used.

Q: What does PIC stand for?
A: Position Independent Code.

Q: How does PIC work?
A: The program is compiled to refer to variables by adding an offset to the current value of the program counter. Therefore if a program is reloaded in different locations, the OS need merely adjust the saved value of the PC to relocate the entire program.

Q: What are the problems that occur with relocation?
A: 1. Works only for static languages.
A: 2. Requires compiler to separate address registers from data registers.
A: 3. Expensive and difficult to implement.

Q: What would be the problem in running a 'C' program using relocation?
A: 'C' allows dynamic memory allocation and casting. i.e. Not Static.

Q: What is the great advantage of using Virtual Memory?
A: Only the parts needed by the program now are loaded into memory, other parts are loaded into memory when the program needs them.
A: This allows the size of a program and its data to exceed the amount of available main memory.

Q: What is an address space?
A: The domain of addresses available to a process.

Q: What are the two main approaches to virtual memory?
A: 1. Paging
A: 2. Segmentation

Q: What is a virtual address?
A: Addresses generated by programs.

Q: Which piece of hardware translates virtual addresses to physical addresses?
A: MMU [Memory Management Unit]

Q: What does the MMU do?
A: Translates virtual addresses to physical addresses at run-time.

Q: How many virtual address spaces are available in a system?
A: One Virtual Address Space per One Process

Q: What is a paged system?
A: A system that divides both virtual and physical address spaces into fixed size pages.

Q: What does one need to know in directory organization? Where do these values reside?
A: 1. physical address of the directory
A: 2. length of the directory and each fragment
A: These values are in the MMU

Q: What happens if a TLB miss occurs?
A: System causes an exception and the OS handles it.

Q: During a context switch, what problem can occur with TLB?
A: When OS switches from P1 to P2, it must make sure that P2 does not use TLB entries belonging to P1, otherwise the two processes will map the same virtual page number, to different physical page numbers.

Q: Name two benefits in using a process ID # in TLB entries.
A: 1. Solves problem of context switches.
A: 2. If TLB is large enough, its contents will survive until a certain process is run again.

Q: If the CPU has virtual address caches, how should they be treated? Why don't physical address caches require such special treatment?
A: Similar to TLBs, i.e. they should be cleared on context switches or they should contain process IDs that are checked on every reference.
A: Physical address caches do not require this treatment as there is only one physical address space.

Q: Where should the OS allocate PTEs?
A: Only to regions of virtual memory the process uses.

Q: What happens if a chosen page (for swapping out) has been modified since being brought in from disk?
A: The OS must first write it out to the disk.

Q: In a split table organization, what does one need to know?
A: 1. Physical address of the beginning of each half of the page table
A: 2. Length (number of PTEs in) each half.

Q: Define what split table organization is.
A: Splitting page table into two:
A: 1. one for code & the heap
A: 2. one for stack

Q: How do virtual addresses refer to user space and system space?
A: A virtual address with a high-bit set refers to system space, one with the high-bit clear refers to user space.

Q: When should processes be allowed to access system space?
A: When they are executing in kernel mode, i.e. during a system call.

Q: How does the hardware ensure that the process is operating in kernel mode?
A: It inspects the high-bit, or by using two sets of permission bits in PTEs, one for user mode, and one for kernel mode.

Q: How many page tables exist for system space? How many page tables exist for user space?
A: Single page table for system space.
A: Several page tables for user space (one for each process).

Q: Why must the page fault handler be kept in memory?
A: Otherwise attempt to access it will itself result in a page fault.

Q: When the TLB misses, why should the lookup of the PTE not go through the MMU in the usual way?
A: Because the PTE lookup may itself miss in the TLB.

Q: If a chosen page (for swapping out) has not been modified since being brought in from disk, what should the OS do?
A: The copy on disk is already up to date, and no disk write is needed.

Q: What is spatial locality?
A: If a location has been referenced lately, locations near it are likely to be referenced soon.

Q: What is temporal locality?
A: If a location has been referenced lately, it is likely to be referenced again soon.

Q: What is the principle of locality?
A: Near future will be about the same as the near past.

Q: On memory access plots, what is the distribution of Spatial locality?
A: Narrow vertical slice, whose width is a few dozen memory accesses' worth of time, will show clumps in accesses.

Q: What would be the optimal policy in page replacement (swapping out)? Why is this not normally applicable in practice?
A: From all the pages in memory, select the page that will be referenced last.
A: This is not applicable because, this requires foreknowledge of the actions of all programs (which is never available).

Q: What are the bounds on how good/bad an algorithm can be for page/replacement?
A: Best: Optimal policy (Page that will be referenced last)
A: Worst: Random Policy (Pick page at random).

Q: Which page does FIFO algorithm select?
A: The page that has been in memory longest.

Q: Which page does LRU select?
A: The page that has been unused for the longest time. [Assuming that it will stay unused for the longest time]

Q: How does LRU work?
A: 1. Requires hardware to record times of access to each page. via page faults or clock ticks.
A: 2. When a new page frame is needed, the OS scans all these timestamps and selects the page frame that was accessed least recently.

Q: Which page does LFU select?
A: Selects the page that was least frequently accessed.

Q: How does LFU work?
A: The algorithm associates a counter with each page frame, and adjusts these counters on every clock interrupt. LFU increments counter of pages that have been accessed since the last clock interrupt.
A: The page with the smallest counter is the one used least frequently.

Q: Where are Referenced and Modified bits located?
A: In PTEs.

Q: If PTEs do not contain Referenced and Modified bits, how can they be simulated?
A: By manipulating the valid bit and the permission bits.
A: In this manner, the OS needs to keep duplicate PTEs, a true PTE for itself and a manipulated PTE for the MMU.

Q: What are the steps involved in Simulating Referenced and Modified bits when a page is referenced?
A: When Process is started:
A: 1. OS marks all its PTEs invalid.
A: 2. Any reference to a page, page fault occurs.
A: 3. OS services fault and sets Referenced Bit, sets Valid Bit and makes page read-only.

Q: What are the steps involved in Simulating Referenced and Modified bits when a page is written to?
A: When a program wants to write on the page:
A: 1. A protection violation trap occurs.
A: 2. If true PTE permits writing, the OS sets the Modified bit.
A: 3. Makes page writable in the MMU's copy of the PTE

Q: What does NRU stand for?
A: Not recently used.

Q: How does NRU differ from LRU?
A: NRU approximates LRU, but also uses the Modified bits as well as the Referenced bits.

Q: Why is NRU and its variants popular?
A: Because they do not require any hardware except R & M bits, and even they can be simulated.

Q: How does NRU work?
A: 1. Periodically clears the Referenced bits of all pages.
A: 2. When page fault occurs, classifies pages into four types:
A:  1. N R, N M
A:  2. N R, M
A:  3. R, NM
A:  4. R, M
A: 3. Removes the oldest page from the lowest numbered class.

Q: Explain the logic behind the classing of pages in NRU?
A: Referenced pages are likely to be referenced again.
A: Modified pages need to be written out to disk.

Q: What is the clock algorithms relation to NRU?
A: It is a variation of NRU.

Q: How does the clock algorithm work?
A: 1. Sweeps through memory in a circular manner.
A: 2. Clears Referenced Bit of each page
A: 3. If the bit is clear when the clock hand reaches its again, this means the page has not been used in the intervening interval.
A: 4. It is then made a candidate for replacement.

Q: Why should the clock have two hands in the clock algorithm?
A: In systems with large memories, junk pages can also be referenced between visits. Two clock hands:
A: 1. To Reset Referenced bits.
A: 2. Test them.

Q: Why would the speed of the clock hand be adjusted in the clock algorithm?
A: Shortage of memory: Speed up for reclaiming more pages.
A: Plenty of Memory: Slow down or stop to reduce overhead.

Q: Why would we prefer a slow moving clock hand in the clock algorithm?
A: To reduce overhead when there is plenty of memory.

Q: What is the aim of 2nd Chance variation of the clock algorithm?
A: To keep write traffic to a minimum.

Q: How does the 2nd Chance algorithm work?
A: Clock hand finds a dirty page that has still not been accessed since the last sweep, and will then make the page a candidate.

Q: What is your recommendation when the 2nd chance variation is applied to a clock with two hands?
A: It then requires a third hand to check the reference bits of pages that have been given a second chance.

Q: What is a free page pool?
A: A free-to-be-replaced page frames available at all times.

Q: What is the significance of using FIFO and a pool?
A: This is effectively an implementation of NRU.

Q: What is the purpose of a Page Write Daemon?
A: The daemon finds diry old pages and writes them to disk, and puts them in the pool whenever a paging disk is unused.

Q: What is the relation between page faults and memory size?
A: As memory size increases => Page faults decrease.

Q: What happens if there is only a small number of page frames?
A: Processes will continually fault for pages that have been just paged out.

Q: What is Belady's anomaly?
A: With some algorithms, more memory in a computer can INCREASE the number of page faults.

Q: Give an example of Belady's anomaly.
A: FIFO algorithm:
A: Page Faults  Page Frames
A:   9      3
A:   10     4

Q: What is Belady's reference string?
A: Sequence of page numbers:
A: 0 1 2 3 0 1 4 0 1 2 3 4

Q: What is thrashing?
A: When a process page faults every few instructions.

Q: Explain the vicious loop that can occur if the number of processes in memory is too high.
A: 1. When # process in memory is too high, each process has only few page frames.
A: 2. Results in high page fault rates.
A: 3. Queue of processes waiting for DISK becomes longer.
A: 4. CPU becomes under utilized.
A: 5. OS Responds to this by bringing more processes into main memory, making situation worse.

Q: What happens to throughput when the number of processes in memory becomes too high?
A: Throughput falls dramatically.

Q: When there is a few processes in memory, what is the bounding of the system?
A: The system is CPU bound.

Q: When there are many processes in memory, how is the system bound?
A: The system is I/O bound.

Q: What is the working set principle?
A: A process should not be run unless the set of pages containing the memory regions it needs regularly ("working set of pages") is in memory.

Q: What should happen to a process that does not have its working set in memory?
A: Should either have more pages allocated to it, or it should be moved to disk altogether.

Q: How can one model the working set of a process?
A: By examining the set of pages the process has referenced in its last N instructions.
A: (N is the parameter of the model).

Q: How is the working set model found in practice?
A: In practice it is approximated, one way is by substituting "clock tick" for "instruction" in the definition.

Q: What are the bounds of the normal page fault rate band?
A: 1. Page fault rate that is unacceptably high
A: 2. Page fault rate that is so low that it can be concluded that the process has too much memory.

Q: What is meant by phases of a program?
A: Some programs can be naturally divided into phases that access different code and different data structures.

Q: When can programs experience a sharp increase in the size of a working set?
A: At the instant of the end of one phase, and the beginning of another phase.

Q: How can the sharp increase in a working set be handled?
A: By making sure that the normal page fault rate band is wide enough to accommodate this behavior.

Q: What happens when processes in memory all have their working sets, and there are page frames available?
A: OS may bring in a new process from disk.

Q: What happens when a processes in memory does not have its working set, and there are no page frames available?
A: A process must be moved out to disk.

Q: What could happen without the working set policy?
A: Multiprogrammed systems thrash under load.

Q: What is demand paging?
A: When a process is created and its page table is in memory but the process does not have any of its pages in memory.
A: Process then FAULTS IN its pages from swap space as it needs them.

Q: Why are swapped out processes not runnable?
A: When a process is swapped out, all its pages and its page table are moved to swap space.
A: A process cannot execute without its page table in memory.

Q: In a paged system without swapping, where would the page tables of processes be kept?
A: Page tables of ALL processes would always stay in memory.

Q: What happens when a process is just swapped in, and demand paging is being used?
Q: What can the OS do the help remedy this situation?
A: The process will generate page faults at a high rate.
A: The OS can PRELOAD the pages it thinks the process will need.

Q: If the OS preloads pages for a process, how is this new PREPAGING system compared to DEMAND PAGING?
A: Prepaging system has a lower overhead then demand paging, which allows better disk scheduling.

Q: What makes the prepaging system difficult to realize?
A: The OS has to guess VERY well which pages it thinks the process will need.

Q: In page size selection, what are the benefits of a LARGE page size?
A: Minimize Overhead
A: Fewer Page Faults
A: Less Disk Accesses
A: Smaller Page Tables

Q: Why do large pages yield fewer page faults?
A: Due to spatial locality.

Q: What are the benefits of having a small page size?
A: Minimize Internal Fragmentation
A: Reduce size of Working Sets

Q: Why are small working sets important on systems with small memories?
A: They allow more processes to be active concurrently.

Q: Why is transfer time on a small page (to disk) negligible as a benefit?
A: Because transfer time is much smaller than seek and latency times.

Q: What is a global allocation system?
A: When the OS searches all memory for a page frame after a page fault.

Q: What is a local allocation system?
A: After a page fault the OS searches only the part of memory that belongs to that process for a page frame. [Unless there are free page frames that are not needed by any other process.]

Q: What is the benefit of using global allocation system?
A: They respond quickly to changes in working set size.

Q: Can local allocation systems respond to changes in working set size?
A: No, they keep the # of pages allocated to each process fixed in the short term. Another mechanism is needed to monitor working set sizes and increase/decrease allocations from time to time.

Q: What is a great disadvantage of a global allocation system? Give an example?
A: Programs in global allocation systems cannot control their own page fault rate;
A: This is bad for example in DBMS.

Q: Describe what shared pages are and give an example of where it is useful?
A: When processes running the same program should refer to the same copy of the code and read-only data of that program.
A: This is useful in timesharing systems, e.g. one copy of shell instead of 80 can save around 20 megabytes.

Q: What is the concept of locking pages?
A: When certain parts of memory should never be paged out, they should be locked in memory.

Q: Give 5 examples of pages that should be locked in memory.
A: 1. page fault routine/handler.
A: 2. process has an outstanding disk read operation, the destination page of the read should not be a candidate for page replacement.
A: 3. new pages that have just entered main memory
A: 4. certain privileged user programs may request that their pages are exempt from paging.

Q: What is segmentation?
A: An alternative to paging. Putting each data structure into its own are of memory, map and swap these areas independently.

Q: What is a segment?
A: An area of memory for a single data structure, that contains its own memory.

Q: In a segmented system, what does the virtual address contain?
A: Segment Number and Offset within the segment.

Q: What does the segment table contain?
A: An entry for each segment of the process.

Q: What does a segment table entry contain?
A: 1. Valid Bit
A: 2. Modified Bit
A: 3. Permissions
A: 4. Base address of segment
A: 5. Length of segment

Q: Do programmers have to be aware of segments?
A: Yes

Q: Do programmers have to be aware of pages?
A: No

Q: What are the dimensions of segmentation and paging?
A: Segmentation - Two Dimensional
A: Paging - One Dimensional

Q: Are segment sizes fixed?
A: No

Q: Which virtual memory concept (paging/segmentation) suffers from which fragmentation?
A: paging suffers internal fragmentation
A: segmenting suffers external fragmentation

Q: Does paging need an address adder?
A: No

Q: Does segmentation need an address adder?
A: Yes

Q: How can segmentation be simulated on a paged system?
A: By viewing contiguous sequence of virtual pages as a segment.

Q: What penalties can arise from simulating segmentation from paging systems? How can these penalties be avoided?
A: 1. Increase page table size
A: 2. Much greater swap space allocated on disk
A: 3. Much greater core dump files.
A: By allocating page table entries, swap space and core file space to a virtual page, only when that virtual page is actually used.

Q: What are the two main ways of creating a process?
A: 1. Issuing a system call specifying what program the new process is to run
A: 2. Issuing a system call that creates a copy of the current process

Q: Why does Unix use system calls that create a copy of the current process? What is the downfall of this method?
A: It is more flexible than specifying what program the new process is to run.
A: The downfall is that it can be more expensive.

Q: What are four important Unix system calls?
A: 1. fork
A: 2. exec
A: 3. exit
A: 4. wait

Q: What does the system call 'fork' do?
A: Makes a copy of the current process
A: Returns the PID of the child process to the parent
A: Zero to the child.

Q: What does the Unix system call 'exec' do?
A: Throws away the current address space
A: Replaces it with the specified program
A: Branches to its start.

Q: What does the Unix system call 'exit' do?
A: Destroys the current process
A: Specifying an exit code.

Q: What does the Unix system call 'wait' do?
A: Waits until a child process exits.
A: Returns the PID of that child and its exit code.

Q: What are two advantages of using 'fork'?
A: 1. Creates exactly what is needed, a copy of the current process.
A: 2. Allows child process to adjust its environment before the call to 'exec'. This makes use of any information available to the parent at the time of the fork, and does not require any changes in the code of the executed program.

Q: What is disadvantage of using 'fork'? How can this problem be solved?
A: Most often, fork is followed immediately by an 'exec'. Therefore the work done in creating a copy of the old process is almost totally wasted.
A: Solution:
A: 1. Use 'vfork', in which the child "borrows" the address space of the parent until it executes exec or exit.

Q: What does COW stand for?
A: Copy on write.

Q: What is copy-on-write?
A: Instead of copying all pages of parent process at the time of 'fork', OS copies only the page tables and marks both sets of pages READ-ONLY and COW.

Q: How does the COW system work?
A: 1. OS Copies only page tables, marks both sets of pages read- only and COW.
A: 2. When a protection violation occurs (for trying to write to read-only page), OS checks COW bit.
A: 3. Copies the page.
A: 4. Updates both PTEs
A: 5. Sets their write permission bits.
