CS703 – Operating Systems: Midterm Important Subjective (45 Solved Q&As)
Virtual University of Pakistan • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS703 Course Page · CS703 MCQ Pack (73 MCQs)
-
What are the five major activities of an operating system in regard to process management?
Topic: Operating System Fundamentals
The five major process management activities of an operating system are: (a) Creation and deletion of user and system processes. (b) Suspension and resumption of processes. (c) Provision of mechanisms for process synchronization. (d) Provision of mechanisms for process communication. (e) Provision of mechanisms for deadlock handling.
-
What are the three major activities of an operating system in regard to memory management?
Topic: Operating System Fundamentals
The three major memory management activities of an operating system are: (a) Keeping track of which parts of memory are currently being used, and by whom. (b) Deciding which processes are to be loaded into memory when memory space becomes available. (c) Allocating and freeing memory space as needed.
-
What are the three major activities of an operating system in regard to secondary-storage management?
Topic: Operating System Fundamentals
The three major secondary-storage management activities of an operating system are: free-space management, storage allocation, and disk scheduling.
-
What are the five major activities of an operating system in regard to file management?
Topic: Operating System Fundamentals
The five major file management activities of an operating system are: (a) Creation and deletion of files. (b) Creation and deletion of directories. (c) Support of primitives for manipulating files and directories. (d) Mapping of files and directories onto secondary storage. (e) Backup of files on stable (nonvolatile) storage media.
-
What is the purpose of the command interpreter? Why is it usually separate from the kernel?
Topic: Operating System Fundamentals
The command interpreter is the interface between the user and the operating system. Its function is simple: to get the next command statement and execute it. It is usually separate from the kernel because it is not needed for the working of the kernel itself; keeping it outside the kernel keeps the kernel smaller and makes it easy to change or replace the interpreter (for example, to give different users different shells) without modifying the kernel.
-
What is the purpose of system calls? What are the main types of system calls?
Topic: Operating System Fundamentals
System calls provide the interface between a process and the operating system. These calls are usually available both from assembly-language programs and from higher-level language programs. The main types are: Process control: end, abort; load, execute; create process, terminate process; get/set process attributes; wait for time; wait event, signal event; allocate and free memory. File management: create file, delete file; open, close; read, write, reposition; get/set file attributes. Device management: request device, release device; read, write, reposition; get/set device attributes; logically attach or detach devices. Information maintenance: get/set time or date; get/set system data; get/set process, file or device attributes. Communications: create, delete communication connection; send, receive messages; transfer status information; attach or detach remote devices.
-
What are the two main functions of an operating system?
Topic: Operating System Fundamentals
An operating system must provide the user with an extended (i.e. virtual) machine, and it must manage the I/O devices and other system resources.
-
What is multiprogramming? What is the difference between multiprogramming and timesharing systems? What is spooling?
Topic: Operating System Fundamentals
Multiprogramming is the rapid switching of the CPU between multiple processes in memory. It is commonly used to keep the CPU busy while one or more processes are doing I/O. Timesharing is a logical extension of multiprogramming in which the CPU is switched between processes so frequently (using timer interrupts and preemptive scheduling) that many users can interact with their programs at the same time; multiprogramming by itself only aims at keeping the CPU busy and does not require interactive response. Spooling (Simultaneous Peripheral Operations On-Line): input spooling is the technique of reading in jobs, for example from cards, onto the disk, so that when the currently executing processes are finished, there will be work waiting for the CPU. Output spooling consists of first copying printable files to disk before printing them, rather than printing directly as the output is generated.
-
What is the key difference between a trap and an interrupt?
Topic: Operating System Fundamentals
A trap is caused by the program itself and is synchronous with the program's execution (for example, a system call or a division by zero), whereas an interrupt is caused by an event external to the processor, such as an I/O device completing an operation, and is asynchronous.
-
What is the difference between kernel mode and user mode? How does having two distinct modes aid in the design of an operating system?
Topic: Operating System Fundamentals
In kernel mode the CPU can execute every instruction and access all of memory and hardware; in user mode only a safe subset of instructions is allowed and direct access to hardware and protected memory is forbidden. Having two modes protects the operating system from erroneous or malicious user programs: a user program that crashes or tries to access protected resources is stopped by the hardware, sensitive operations can only be performed by the kernel through controlled system calls, and this clear boundary makes the system more reliable and secure.
-
Explain how the separation of policy and mechanism aids in building microkernel-based operating systems.
Topic: Operating System Fundamentals
The microkernel implements only the basic mechanisms (such as message transport, loading programs into memory and device handling) in the kernel, while policy decisions are made by user-level servers in user space. Because mechanisms do not dictate policy, policies can be changed, replaced or extended by modifying user-level services without touching the kernel, which makes the system flexible, modular and easier to maintain.
-
What are the advantages and disadvantages of the microkernel architecture?
Topic: Operating System Fundamentals
Advantages: (a) adding a new service does not require modifying the kernel; (b) it is more secure, as more operations are done in user mode than in kernel mode; and (c) a simpler kernel design and functionality typically results in a more reliable operating system. The primary disadvantage of the microkernel architecture is the overhead associated with inter-process communication and the frequent use of the operating system's messaging functions in order to enable the user process and the system service to interact with each other.
-
For each of the following system calls, give a condition that causes it to fail: fork, exec and unlink.
Topic: Operating System Fundamentals
fork fails when the system has reached its limit on the number of processes (or there is not enough memory) to create a new process. exec fails when the named file does not exist, is not executable, or is not in a recognizable executable format. unlink fails when the file does not exist or the user does not have permission to remove it (for example, the directory is not writable by the user).
-
In the fork_test() function given below, how many processes would be created in total, excluding the main process that called fork_test()? How many times will "Whatsup" be printed? Explain briefly. void fork_test() { if (fork() != 0) { if (fork() != 0) fork(); else printf("Hello 1"); } else { if (fork() != 0) { printf("Hello"); } else { fork(); } } printf("Whatsup"); }
Topic: Processes and Threads
Five processes are created, excluding the main process that called fork_test(). The "Whatsup" line is printed six times, because each process (the original plus the five created) reaches and executes this line. The condition (fork() != 0) is false in a child process, because fork() returns 0 in the child; it is true for the parent, because the parent receives the child's non-zero PID (and -1 would indicate an error). Tracing the code: the parent passes the first test, passes the second test and forks again; that new child fails the second test and prints "Hello 1". The child of the first fork fails the first test, enters the else part; there the parent of that branch passes the inner test and prints "Hello", while its child fails the test and forks once more. In this way five new processes are created, and since all six processes execute the final printf, "Whatsup" is printed six times.
-
How is a thread created? Sometimes a thread may not be created — why?
Topic: Processes and Threads
A thread is created by the operating system (or thread library) when a process requests it, for example through a call such as pthread_create() in POSIX. The system allocates a thread control block, a separate stack and a register set for the new thread, records it in the process's thread table, and places it on the ready queue so the scheduler can run it; the thread shares the code, data, heap and open files of its parent process. Sometimes the thread cannot be created: the system may have reached the maximum number of threads allowed per process or for the whole system, or there may not be enough memory/resources (for example, stack space) available, in which case the creation call fails and returns an error.
-
Why is it considered that threads are harmful?
Topic: Processes and Threads
Threads are a difficult thing to handle for most programmers. Bugs can be introduced easily by the programmers while using threads, and the most annoying thing is that these are hard to find and even harder to fix. The things are painful for experts, so inexperienced programmers consider threads harmful. During synchronization, it is required that threads must coordinate access to shared data with proper locks, and missing a lock results in corruption of data. Threads also cause deadlocks if used inefficiently or carelessly. The main purpose of using threads is concurrency, but this is hard. Hence threads are considered harmful and are avoided by normal programmers.
-
Give some reasons to use threads in a beneficial way.
Topic: Processes and Threads
Threads can be used for concurrency, and the responsiveness of applications is increased when threads are used with care. Performance and utilization of multi-core, multi-CPU systems is increased with multiple threads running on multiple CPUs, each thread running in parallel on a different processor. The efficiency of high-end servers is increased. Threads share the memory and resources of the process to which they belong, and code sharing allows an application to have several different threads of activity all within the same address space.
-
Which are the classical issues related to threads?
Topic: Processes and Threads
Synchronization and deadlocks are the main issues related to threads, and the classical problems are: 1. Bounded Buffer Problem 2. Readers and Writers Problem 3. Dining Philosophers Problem
-
A multithreaded solution using multiple kernel threads gives better performance than a single-threaded solution on a single-processor system. Under what conditions does this occur?
Topic: Processes and Threads
When a kernel thread suffers a page fault, another kernel thread can be switched in to use the interleaving time in a useful manner. A single-threaded process, on the other hand, will not be capable of performing useful work when a page fault takes place. Therefore, in scenarios where a program might suffer from frequent page faults or has to wait for other system events, a multithreaded solution would perform better even on a single-processor system.
-
In lectures, three methods to achieve concurrency were studied. What is the difference between the second method (single process, multiple events) and the third method (threads)?
Topic: Processes and Threads
In the second method, a single process handles many activities using an event-driven style: it issues non-blocking operations and uses an event loop to react to completions, maintaining the state of each activity explicitly in its own data structures. There is only one thread of control and one stack, so there are no race conditions, but the programmer must save and restore state manually and structure the program as state machines. In the third method (threads), several threads run inside one process, each with its own stack and program counter, sharing the same address space; the kernel schedules them preemptively, so blocking calls are natural to write, but shared data must be protected with locks and synchronization, which introduces races and deadlocks.
-
Describe what problems would happen when multiple threads execute the following C statement, and justify your answer. { static int I; I++; }
Topic: Processes and Threads
1. Incorrect ordering / lost update: the statement I++ is not atomic — it is a load, an increment and a store. When two threads increment the counter concurrently, both may load the same old value, so the result can be 1 instead of 2. 2. Concurrency issues: static fields exist only once, so if code reads and writes static (shared) fields, threads can read stale data and produce wrong outputs when they update the shared resource concurrently. 3. Race condition: the outcome depends on which thread reaches the code first and on the thread scheduling order, so repeated runs can give different, unpredictable results. 4. Deadlock can also arise in such code once locks are added carelessly to protect the shared variable: two threads may each lock a resource the other needs and wait forever. Hence shared data like the static variable I must be protected (for example with a mutex) so that the increment executes atomically.
-
Review the Readers/Writers problem discussed in Lecture 12. Write the code for the Reader() and Writer() functions when readers are given priority over writers, keeping the problem constraints in mind.
Topic: Synchronization
Shared data: semaphore mutex = 1 (protects readcount); semaphore wrt = 1 (writer access / first reader locks, last reader unlocks); int readcount = 0. Writer(): wait(wrt); ... writing is performed ... signal(wrt); Reader(): wait(mutex); readcount++; if (readcount == 1) wait(wrt); signal(mutex); ... reading is performed ... wait(mutex); readcount--; if (readcount == 0) signal(wrt); signal(mutex); Because a steady stream of readers can keep readcount above zero, writers may starve in this readers-priority version.
-
Reader/writer locks are used to solve the readers/writers problem. In the semaphore implementation, why do AcquireReadLock() and AcquireWriteLock() perform P and V operations on the mutex semaphore? Could readers or writers be starved in this implementation? Suggest how a starvation-free implementation can be achieved.
Topic: Synchronization
The mutex semaphore protects the shared bookkeeping variables of the lock (such as the reader count and the lock state). AcquireReadLock and AcquireWriteLock must read and update this state atomically; without the P/V pair on mutex, two threads could interleave their updates and corrupt the count, admitting a writer while readers are active or losing track of waiting threads. Starvation is possible: in the usual readers-preference version, a continuous stream of readers keeps the lock in read mode and a writer can wait indefinitely (writer starvation); symmetric writer-preference versions can starve readers. A starvation-free policy can be implemented by serving requests in arrival order: add a fair (FIFO) queueing/turnstile semaphore that every reader and writer must pass through in order, so that once a writer is waiting, later readers cannot overtake it, and readers already inside finish and let the writer proceed; this bounds the waiting time of both readers and writers.
-
How should threads coordinate? How should they wait for an event or a state change?
Topic: Synchronization
A thread, while holding the lock, may change the variables constituting the condition expression. It should then call signal to notify a single waiting thread to resume execution, or broadcast to wake all waiting threads. Signal and broadcast move waiting threads off the condition variable's queue and queue them on the associated lock. Only after the signaling/broadcasting thread releases the lock may these threads resume execution. However, it is possible that other threads were previously waiting on the lock, so the waiting threads are not guaranteed that the condition expression is true. Rather, returning from wait is considered a hint that the expression may have become true. After resuming, the thread must test the expression again before proceeding. Hence, threads commonly wait within a while loop that tests the condition expression.
-
What are conditional critical regions? What are their limitations, and how can these limitations be overcome?
Topic: Synchronization
Conditional critical regions are the regions in a program that must be executed by one process at a time; no other process can execute that region at the same time. When condition variables are used for locking purposes, the critical regions are referred to as conditional critical regions. Their limitations are: with conditional critical regions, waiting occurs without any changes to shared state; the resource concept is unreliable; context switching is inefficient; and the scheduling mechanism is too restrictive. These limitations can be removed using condition variables.
-
What are condition variables? What are their limitations, and how can these limitations be overcome?
Topic: Synchronization
Condition variables are queues of waiting threads. They support three operations: wait, signal and broadcast. Logically, every condition variable is associated with one (or more) Boolean condition expressions and a mutex lock. Condition variables are used to complement locks by allowing a program to specify the order of execution. There are two limitations: (1) the signal operation is explicit, so a programmer may forget to call signal when changing shared state; (2) condition variables do not nest within multiple levels of mutex locks, because only the innermost lock is released when waiting — as a result, deadlock may result if the blocked thread can only be woken by code that acquires a lock still held by the waiting thread. These limits are removed when condition variables are used with transactional memory.
-
What is the lost wakeup problem, and how can it be resolved?
Topic: Synchronization
A signaling or broadcasting transaction may execute concurrently with a transaction that it woke up. If the waking transaction completes before the signaling transaction, it is called the (lost) wakeup problem: the waking transaction may view shared state from before the signaling transaction, and hence from before the logical condition it awaits is visibly changed, so the wakeup is effectively lost. The wakeup problem may be resolved by the deferred signal approach, or by the speculative signal approach.
-
What are the requirements and implications of the two implementations of condition variables for transactional memory (deferred signal and speculative signal)?
Topic: Synchronization
For the deferred signal approach, the requirement and implication is commit actions: signals are deferred and only take effect when the signaling transaction commits, so the implementation must be able to perform actions at commit time. For the speculative signal approach, the requirements and implications are escape actions and robust conflict detection: a waiting transaction may be woken speculatively before the signaler commits, so the system must support escaping the transaction to perform non-transactional actions and must detect conflicts robustly so that a speculative wakeup based on state that is later rolled back can be handled correctly.
-
Write a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself.
Topic: Synchronization
monitor bounded_buffer { int items[MAX_ITEMS]; int numItems = 0; condition full, empty; void produce(int v) { while (numItems == MAX_ITEMS) full.wait(); items[numItems++] = v; empty.signal(); } int consume() { int retVal; while (numItems == 0) empty.wait(); retVal = items[--numItems]; full.signal(); return retVal; } }
-
Explain, in your own words, how the proposed approach manages to avoid deadlocks when unstructured locking is used.
Topic: Synchronization
The proposed approach says that deadlock cannot occur when we have the requested lock and its future lock set available. The future lock set is the set of locks acquired from the point where a lock is requested until its matching unlock is found. The approach tracks simple effects (empty sequences of lock/unlock events) and continuation effects (the effect of code on its following expression). Notes are added to lock operations according to their continuation effects; continuation effects are calculated statically, but future lock sets are computed at run time. When a function is called, its continuation effect is pushed on the stack until the call is fully executed, and during this the locks are identified and added to the lock set. At run time, a lock operation proceeds only when its whole future lock set is available to the requesting thread, so a thread never holds one lock while waiting for another in a way that could form a cycle. The approach gives only a single (composite) lock to every lock operation, which increases the degree of parallelism.
-
How is static analysis performed for this approach, and what are its limitations?
Topic: Synchronization
Static analysis is performed in four phases. (1) Pointer analysis: the heap and stack state is formulated at each point of the program by a pointer analysis based on symbolic expressions, treating heap allocation in a context-sensitive manner; the output is a mapping from each expression to a set of abstract locations (formal parameters, global variables or heap-allocated locations). (2) Effect interference: a forward dataflow algorithm runs on the functional control flow graph to compute the effect of each function, propagating output effects to successors until a fixed point is reached. (3) Loops: lock counts in effects flowing from back edges must equal the input effect of the same node, so loop effects can be encoded efficiently from entrance to exit. (4) Effect optimization: common prefixes and suffixes are factored out and nested loops are lifted to reduce the number of branches; the CPU-intensive dataflow algorithm is triggered only for functions known to contain lock operations. Limitations: library code cannot be handled directly (library functions are assumed to have empty effects unless the user adds notes); the analysis cannot handle non-local jumps (including signals) and inline assembly; and the pointer analysis is not capable of handling all programs precisely.
-
Differentiate between preemptive and non-preemptive scheduling algorithms, and give one example of each.
Topic: CPU Scheduling
In non-preemptive (cooperative) scheduling, once a process is given the CPU it keeps it until it terminates or blocks voluntarily (for example, for I/O); the scheduler cannot take the CPU away from it. Example: First-Come First-Served (FCFS). In preemptive scheduling, the operating system can suspend a running process and allocate the CPU to another process, for example when a higher-priority process arrives or a time quantum expires. Example: Round Robin (and Shortest Remaining Time First). Preemptive scheduling improves responsiveness and fairness but needs timer hardware and incurs context-switch overhead, and it requires care with shared data in the kernel.
-
Consider a variant of round robin in which the entries in the ready queue are pointers to the PCBs. (a) What would be the effect of putting two pointers to the same process in the ready queue? (b) What would be the major advantage and disadvantage of this scheme? (c) How would you modify the basic round-robin algorithm to achieve the same effect without duplicate pointers?
Topic: CPU Scheduling
(a) In effect, that process will have increased its priority, since by getting time more often it is receiving preferential treatment. (b) The advantage is that more important jobs could be given more time, in other words, higher-priority treatment. The disadvantage, of course, is that shorter (and other) jobs will suffer, receiving a smaller share of the CPU. (c) Allot a longer time quantum to processes deserving higher priority. In other words, have two or more quanta possible in the round-robin scheme.
-
What is rate-monotonic scheduling? How are priorities assigned in it?
Topic: CPU Scheduling
The rate-monotonic scheduling algorithm is a real-time scheduling algorithm that uses preemptive scheduling with static (fixed) priorities. Priorities are assigned inversely to the period of each task — that is, on the basis of the periods — giving higher (better) priority to tasks with shorter periods. Because priorities never change at run time, the algorithm is simple to implement and its schedulability can be analyzed in advance.
-
Which are the necessary conditions for deadlock to occur?
Topic: Deadlock
There are four necessary conditions, and all four of them must hold simultaneously for a deadlock to occur: Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait. I. Mutual Exclusion means there must be at least one resource which can only be used by a single process at a time (non-shareable mode); if another process requests this resource, it must be delayed until the resource is released. II. Hold and Wait means a process is holding at least one resource and waiting for other resource(s) held by other process(es). III. No Preemption means no process can be forced to release the resources it is holding; resources are released voluntarily. IV. Circular Wait means there is a set of processes such that P0 waits for a resource held by P1, P1 waits for a resource held by P2, and so on up to Pn, which waits for a resource held by P0.
-
Draw (describe) a resource allocation graph that shows a deadlock condition.
Topic: Deadlock
Consider two processes P1 and P2 and two single-instance resources R1 and R2. P1 holds R2 and requests R1 (edges: R2 assigned to P1; P1 waiting for R1). P2 holds R1 and requests R2 (edges: R1 assigned to P2; P2 waiting for R2). The graph contains the cycle P1 -> R1 -> P2 -> R2 -> P1. Since each resource has only one instance, this cycle is a deadlock: P1 can never get R1 until P2 releases it, and P2 can never get R2 until P1 releases it, so neither can proceed.
-
How is it possible to prevent deadlocks?
Topic: Deadlock
There are four necessary conditions which must hold simultaneously for a deadlock to occur, so deadlock can be prevented by implementing some methodology that guarantees that at least one of the four necessary conditions does not hold. Relaxing the first three conditions, i.e. mutual exclusion, hold and wait, and no preemption, is not always useful — it may cause low utilization of resources and starvation. Circular wait is the ultimate choice; it is the most suitable condition to attack, i.e. ensuring that circular wait never holds. The simple methodology used for this purpose is to order all the resources and require that each process always requests resources in increasing order. Hence there may never be a process waiting for a low-numbered resource while holding a higher-numbered resource, ensuring that a cycle is impossible. So, by ensuring there is no circular wait, deadlocks can be prevented.
-
There are p processes competing for r identical resource units. Each process needs a maximum of m resource units (where m is at most r). (a) Under what condition can no deadlock occur? (b) Give an example of a request sequence leading to deadlock.
Topic: Deadlock
(a) In the worst case, every process could be holding m - 1 resources and waiting for one more. Deadlock is therefore impossible if there is at least one extra resource beyond this worst case, i.e. if r is at least p(m - 1) + 1, because then at least one process can obtain all m units it needs, run to completion and release its resources, after which the others can proceed one by one. (b) Suppose p processes each request and are granted m - 1 of the r = p(m - 1) resources, so all resources are allocated. Now every process requests one more resource; none is available, so every process waits. All processes are collectively holding all the resources, all are in the wait state, and no process will ever release its resources — deadlock occurs.
-
Write a resource allocation algorithm which will prevent deadlock.
Topic: Deadlock
A simple deadlock-preventing allocation algorithm for processes requesting identical resources is: If the process has ever acquired any resources before, do not serve the (new) request — the process must first consume and release the resources it already holds. Else, if no resource is remaining free, do not serve the request. Else, if no resource is free at the moment, wait until all resources are free. Otherwise, grant the process access to the resources it needs as one individual (all-at-once) allocation. Because a process receives all the resources it needs in a single grant and never holds some resources while waiting for others, the hold-and-wait condition (and hence deadlock) is prevented.
-
Three processes are sharing 4 resources of the same type in a system. Every process needs 2 resources. Show that the system is deadlock-free.
Topic: Deadlock
If the system were deadlocked, it would imply that each process is holding one resource and is waiting for one more. Since there are 3 processes and 4 resources, even if each of the three processes holds one resource, one resource remains free, so one process must be able to obtain the second resource it needs. This process requires no more resources and therefore it will return its resources when done, after which the remaining processes can also obtain two resources and complete. Hence the system can never be deadlocked.
-
Suppose that a system is in an unsafe state. Show that it is possible for the processes to complete their execution without entering a deadlock state.
Topic: Deadlock
An unsafe state is not the same as a deadlock state: it only means the system cannot guarantee that all processes will complete for every possible sequence of requests. If the processes do not actually request their maximum claims, or if they release resources before requesting more, all of them can still complete. For example, with 12 free resource units in total, suppose P0 holds 5 (max 10), P1 holds 2 (max 4) and P2 holds 2 (max 9), leaving 3 free; the state is unsafe because the remaining need of P0 (5) and P2 (7) cannot both be met safely in some order. But if P1 finishes and releases its 2 units, and P2 then requests and releases resources without ever needing its full maximum at the same time as P0, all three processes can run to completion one after another. So an unsafe state may, but need not, lead to deadlock.
-
Describe the working of implicit and explicit memory allocators.
Topic: Dynamic Memory Allocation
In an implicit allocator, the application allocates memory explicitly (for example with malloc) but freeing is implicit — a garbage collector automatically determines when allocated blocks are no longer used and frees them; the application never calls free. In an explicit allocator, the application is responsible for both allocating and explicitly freeing memory (malloc/free style): it must call free on a block when it is done with it. Explicit allocation is the style used by C, while languages such as Java and Lisp use implicit allocation (garbage collection). A related distinction is between implicit and explicit free lists: an implicit free list scans all blocks (free and allocated) using the block sizes, while an explicit free list links only the free blocks in a list.
-
If the size of the header and footer is one 4-byte word and no zero-size payload is allowed, find the minimum block size for each case: (a) single-word alignment, both header and footer; (b) single-word alignment, only header; (c) double-word alignment, both header and footer; (d) double-word alignment, only header.
Topic: Dynamic Memory Allocation
(a) Single-word alignment, header and footer: minimum payload is one word (4 bytes), so minimum block = 4 (header) + 4 (payload) + 4 (footer) = 12 bytes. (b) Single-word alignment, only header: minimum block = 4 (header) + 4 (payload) = 8 bytes. (c) Double-word alignment, header and footer: the block size must be a multiple of 8 bytes; 4 (header) + payload + 4 (footer) with a payload of at least one word gives 12, which is not a multiple of 8, so the payload must be padded to 8 bytes, giving a minimum block of 16 bytes. (d) Double-word alignment, only header: 4 (header) + 4 (payload) = 8 bytes, which is already a multiple of 8, so the minimum block is 8 bytes.
-
What is the algorithmic order of the worst-case allocation time and the worst-case freeing time of the following dynamic memory allocation techniques? (a) Implicit free lists (b) Explicit free list, with coalescing while freeing (c) Simple segregated free lists, without coalescing while freeing.
Topic: Dynamic Memory Allocation
(a) Implicit free list: allocation requires scanning the blocks of the heap, so worst-case allocation time is linear in the total number of blocks in the heap; freeing (with boundary tags) takes constant time. (b) Explicit free list: allocation searches only the free blocks, so worst-case allocation time is linear in the number of free blocks; freeing, including coalescing with neighbouring free blocks using boundary tags, takes constant time. (c) Simple segregated free lists: allocation only searches the list of one size class, so worst-case allocation time is (near) constant for a request (in the worst case, linear in the number of free blocks in that size class); freeing is constant time, since the block is simply inserted into its size-class list and no coalescing is performed.
-
What are the difficulties with designing system software?
Topic: Dynamic Memory Allocation
Designing system software is difficult because it must run for long periods without failing while managing shared hardware resources for many mutually distrustful programs at once. It must deal with concurrency and synchronization (races and deadlocks), provide protection and security between users and processes, remain efficient because every program depends on it, handle unpredictable asynchronous events such as interrupts, and at the same time present simple, convenient abstractions (files, processes, virtual memory) over complicated, very different hardware. Bugs in system software are especially costly because they can crash or compromise the whole machine rather than a single application.