Programming · 30 Aug 2014 · 4 min read
Operating systems: important interview questions
Here are some of the more common interview questions on operating systems concepts, with straightforward answers to each.
What is a semaphore?
A semaphore is a protected variable, or abstract data type, that gives a simple way to control access to a shared resource across multiple processes in a parallel programming environment. It’s a standard mechanism operating systems use to let processes share a resource safely.
What is memory management?
Memory management is the process of managing a computer’s memory: allocating portions of it to programs when they request it, and freeing it again once it’s no longer needed. Managing main memory well is critical to how a computer system performs overall.
What is virtual memory?
Virtual memory is a memory management technique built for multitasking kernels. It virtualises a computer’s hardware memory devices — RAM modules, disk storage, and so on — so a program can be designed as if there’s a single memory device, and as if it has sole access to that “virtual” RAM as one contiguous working address space.
What are paging and segmentation?
Paging divides primary memory into small, equal-sized partitions called page frames (typically 256, 512, or 1K), and divides a process into same-sized blocks called pages. Only the pages currently being referenced are brought into memory, and a page table tracks the mapping. Paging suffers from internal fragmentation.
Segmentation, by contrast, maps segments — representing data structures, modules, and so on — into variable-sized partitions. Not all of a process’s segments need to be loaded at once, and they don’t have to sit in contiguous memory.
What’s the difference between internal and external fragmentation?
Fragmentation happens in a dynamic memory allocation system when free blocks of memory become too small individually to satisfy new requests, even though enough total space exists.
External fragmentation occurs when an allocation algorithm hands out memory in a way that leaves small, unusable gaps behind it. Enough usable memory may exist in total, but not as one contiguous block, so a request can fail even though the space technically exists.
Internal fragmentation is the space wasted inside a block that’s already been allocated, because the block is slightly larger than what was actually requested. That leftover space sits unused until the block is freed.
What is an operating system?
An operating system is software — a mix of programs and data — that runs on a computer, manages its hardware resources, and provides the common services needed to run application software.
What are the functions of an operating system?
The main functions of an operating system are resource management, data management, task (job) management, and providing a standard means of communication between the user and the computer.
What is a TLB?
A translation lookaside buffer (TLB) is a CPU cache that memory management hardware uses to speed up virtual-to-physical address translation. Every current desktop and server processor architecture, including x86, uses a TLB, and it’s a standard part of any hardware that supports virtual memory.
What’s the difference between multiprogramming, multitasking, and multiprocessing?
Multitasking describes running more than one application, program, or task on a single processor. Multiprocessing is the ability to use more than one processor (CPU) within a single machine.
What are the disadvantages of semaphores?
A semaphore is a synchronisation tool: a variable that holds non-negative integer values, accessed and modified only through two operations, wait() and signal(). Their main drawbacks are that semaphores are unstructured and don’t support data abstraction. Alternatives include critical regions, conditional critical regions, monitors, and message passing.
What is a deadlock, and when does it occur?
A deadlock is a situation where two or more competing processes are each waiting on the other to finish, so neither ever does. A deadlock can only arise when four conditions hold at the same time:
- Mutual exclusion — only one process at a time can use a given resource.
- Hold and wait — a process holding at least one resource is waiting to acquire additional resources held by other processes.
- No preemption — a resource can only be released voluntarily, by the process holding it, once that process has finished its task.
- Circular wait — a chain of waiting processes forms a loop: P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2, and so on, until the last process in the chain is waiting for a resource held by P0.