Basics Flashcards
Name a central operating system abstraction
Process/Thread
File
Virtual Memory
Where or when does the process consume additional system resources? Give two examples.
The process abstraction introduces a runtime overhead on context switches, that is by saving and restoring the register state. Each process/thread also requires its own stack, which increases the memory footprint of the application.
Why can system calls in an operating system like Linux conceptually not be replaced by procedure calls?
An important task of a system call is to change the privilege level of the CPU when entering the kernel. This can’t be done with a procedure call and would force the OS to give up the separation between user and kernel mode.
Give a reason besides simplicity why applications usually do not invoke system calls themselves but use language or system libraries instead.
Compatibility/Portability.
If the system call interface is not stable, updating the OS would require developers to also update their applications and potentially keep and maintain different versions. But even with a stable interface, invoking a system call is highly architecture specific. Language and system libraries help to abstract away from such details, making applications more portable.
What other CPU mechanism besides the trap instruction could technically be used to synchronously enter the kernel from user mode?
CPU exceptions
software interrupts
Name and explain two basic techniques for an operating system to wait for the completion of an input/output operation.
1) Programmed I/O, Polling: The CPU busy waits for the completion of the I/O operation by repeatedly querying a status register of the device.
2) Interrupts: The device raises a previously determined interrupt line or crafts a message for an interrupt controller. The CPU then jumps to a configured interrupt
service routine upon receiving the interrupt, thereby signaling the completion of the I/O operation
Explain what is meant by cooperative multitasking. Which system call plays a special role in this context?
With cooperative multitasking, the OS doesn’t forcefully preempt processes or threads to perform a context switch. Instead, tasks are expected to voluntarily release the CPU, that is cooperate with the other processes. Releasing the CPU is usually done by invoking the yield() syscall.
Where or when does the file abstraction consume additional system resources? Give two examples
Translating file offsets to physical sector offsets slows down sector accesses. Respective data structures for address translation must be created, maintained, and stored on the storage device.
Where or when does the virtual memory abstraction consume additional system resources? Give two examples
It comes with additional costs for address translation (TLB misses, page faults). Switching between virtual address space is also a costly operation, especially when TLBs have to be flushed. Keeping management structures such as page tables consumes processor time and memory.
Describe a situation in which the process/thread abstraction saves system resources.
If the current process waits for I/O, switching to another process in the meantime can increase the overall system utilization; it saves CPU time.
Describe a situation in which the file abstraction saves system resources.
The additional indirection provided by files allows unallocated areas to transparently return zero-sectors, saving the space on the storage device.
Describe a situation in which the virtual memory abstraction saves system resources.
The possibility to safely share identical data between processes, thus eliminating the need to hold multiple copies in memory.
Name one example of a mechanism as well as a policy of an operating system
Mechanisms: Dispatcher/threads, swap files
Policies: Scheduler, page replacement policy
Which advantage does the separation between mechanism and policy provide?
More flexibility: Replacing the policy doesn’t require rewriting the mechanism.
Explain the difference between concurrency and parallelism.
Concurrency: The OS implements context switching between tasks on a single CPU
Parallelism: Multiple tasks run on multiple CPUs at the same time
In which situations do concurrency and parallelism each increase the performance of the system
Concurrency allows other tasks to run while one task waits for I/O – the overlap between CPU and I/O improves performance
Parallelism increases performance
whenever multiple tasks are runnable at the same time
Java is commonly viewed as an easier programming language than C. Explain one reason why it is, however, more difficult to write an operating system kernel in Java
compared to C.
> Java uses memory management based on garbage collection – the garbage collector itself adds to the work required to program a kernel and cannot be written in Java alone
Java does not allow access to arbitrary memory, although the OS frequently needs such access to arbitrary addresses to access device registers or to perform memory management
limited direct execution.
User-space code is allowed to perform most operations directly on the CPU without OS intervention, and only those operations which affect the safety or stability of the system are reserved for the OS
Microkernel operating systems implement device drivers and OS components as separate processes in user space instead of placing them in the shared kernel space. Name one advantage and one disadvantage of this architecture.
+Bugs in drivers have less impact on the safety/stability of the whole system. For example, accesses to invalid pointers don’t have the potential to crash the OS kernel.
-The architecture causes increased overhead compared to traditional OS. As the system is partitioned with finer granularity, more system calls and IPC operations are required to communicate between drivers and the kernel
Garbage collection
Garbage collection is an automatic memory management technique used in programming languages and environments where memory allocation and deallocation are done by the language runtime rather than by the programmer. The goal of garbage collection is to identify and free memory that is no longer being used by the program, in order to prevent memory leaks and improve program performance.
Removing the separation into user and kernel mode can make sense in specialized environments such as on embedded devices or where only a single fixed application is run on the operating system. Name and explain one advantage and one disadvantage of running the application and operating system together in kernel mode.
+ A potentially faster execution as expensive system calls can be replaced with cheap function calls.
- Bugs in the application can easily corrupt OS data structures and thereby reduce reliability and stability.
What is the role of the system call dispatcher?
The syscall dispatcher performs the lookup in the system call table and jumps to the handler.
Multi-processor systems are usually capable of delivering interrupts to an arbitrary processor. Give two reasons why the choice of the target processor may affect system performance.
> If the interrupt is delivered to a busy processor instead of an idle one, the running process is unnecessarily interrupted and delayed.
> Each processor has its own cache. How efficiently the interrupt can be handled depends on the data in the cache. Processors which have recently accessed the data required to process the interrupt will perform significantly better than processors with a “cold” cache.
> If one processor processes all interrupts, the chance is high that interrupts are not handled immediately by the OS, which increases the response time to the user input.
The .bss segment of an ELF file is enlarged. How does this affect the file size and the consumption of virtual and physical memory? Assume demand paging.
> File size doesn’t change. Because being all zeroes, the .bss
segment is not actually stored on the disk.
> Virtual memory increases according to the change in the segment size because the segment has to be represented in virtual memory to allow access.
> Physical memory may increase, depending on if the newly reserved space is actually accessed. Also depends on other paging decisions.
Why does it make sense to use an operating system even if only one application is to be executed on a system?
> Avoid engineering efforts to support necessary devices and perform basic OS tasks such as handling I/O, scheduling and dispatching threads, or memory management.
> Application is not restricted to run only on the particular system due to the OS abstractions
In a system call, parameters can be passed via the stack or registers. Explain an additional measure that must be taken when passing parameters by stack to ensure the security of the system.
The parameters need to be copied from the user-mode stack of the thread to its kernel-mode stack of the thread to its kernel mode stack before verification so that they can’t be manipulated by other user-mode threads that are running concurrently.
Without taking security into account, name one advantage and one disadvantage of passing parameters via registers.
+saves memory accesses
-limited number of parameters
A try/catch block handles two exceptions: ArithmeticException and IllegalArgumentException. Which of the exceptions might have originally been raised by the CPU? Give an example of such a situation.
ArithmeticException, for example, due to a division by zero.
To synchronize a critical section in the kernel, a spinlock is used. What additional action may be necessary to ensure correct synchronization and when is it necessary?
It might be necessary to also disable interrupts if the critical section accesses a state that may also be touched by interrupt handlers.
Describe the terms interrupt vector and interrupt service routine.
Interrupt Vector: Either directly the entry address of an interrupt handler or the index into an array of such addresses, called the interrupt vector table.
Interrupt Service Routine: An ISR is a piece of system code that handles an interrupt. It is often part of a device driver and may be reading or writing device registers and device memory.
Explain an advantage and a disadvantage of static versus dynamic linking of libraries
+no external dependencies as libraries are linked to a single executable
+link time optimization (LTO) is possible as libraries are available at the link time of executable
+potentially smaller memory footprint because only required functionality is included
+smaller load time because no dependency resolution and dynamic linking
-higher physical memory consumption due to missing sharing opportunities
-larger executable distribution and storage size
-higher security risks, as all executables that share a vulnerable library have to be relinked and updated
Name a segment of an ELF file that can be shared between processes and another segment that cannot be shared. Give reasons why each segment can be shared or cannot be shared
Generally, ELF segments can be shared if they are read-only and thus do not receive process private data. Accordingly, .text and .rodata can be shared, whereas .data and .bss cannot be shared.
Name two ways of passing the parameters of a system call to the kernel. Which of these ways would you prefer? Explain your answer.
Parameters can be passed either on registers or on the stack. Passing them in registers is preferable because registers can be accessed faster than memory, which may improve system call performance.
How does the operating system know that a non-privileged process has tried to execute a privileged instruction?
The CPU generates an exception in that case.
What do the following abbreviations stand for?
TCB
IPC
TCB: Thread Control Block
IPC: Interprocess Communication
Give two pairs of hardware resources and corresponding operating system abstraction.
Hardware Resource OB Abstraction
CPU time Process/Thread
RAM/Memory Virtual address space
Disk File