OS 1 Flashcards
What is an operating system?
A main program that ALWAYS runs on the processor from system startup, and manages the execution of other programs
What are the steps involved in executing a program?
- When system starts, execute operating system.
- Load additional programs into memory.
- Request execution of program using a system call.
- Operating system starts execution of program.
What is a system call?
A mechanism that allows user-level programs to request services or resources from the operating system’s kernel, such as file operations, memory management, or process control.
What are the three elements of a computer system?
- Users (humans, machines)
- Software (application programs, operating system, system programs)
- Hardware - CPU, memory, battery, input/output devices
What are application programs?
Software designed to perform specific tasks or functions for end-users on a computer system, typically operating on top of the system software in a device
- e.g., word processing, web browsing, data analysis
What are system programs?
Software that manage and support a computer’s core functions, facilitating communication between hardware and application programs
What is the CPU?
The central processing unit, the primary component of a computer that performs calculations, executes instructions, and manages data processing tasks to run programs and operations
What is a device controller?
A hardware component managing the communication between the CPU and external devices (such as storage drives, printers)
- translates data and control signals between them
What is an interrupt?
A signal sent to the CPU by hardware or software to temporarily halt its current operations and redirect its attention to a higher-priority task or event
What is a device controller buffer?
A temporary storage area that holds data being transferred between a peripheral device and the system’s memory, helping to manage data flow and prevent bottlenecks during communication
Describe as an example the process of a computer accessing data on a hard drive. Why is this example inefficient? How can some of these issues be fixed?
- CPU tells device controller what data it wants to read (writing command + address in device controller registers)
- Device controller accesses the hard drive.
- Hard drive recovers data on disk and writes it in the device controller buffer.
- Device controller tells the CPU that the data is ready using an interrupt.
- CPU reads data in the device controller and copies it in memory.
CPU wastes time waiting for I/O operation to complete. CPU performs many copy operations. CPU must treat many interrupts.
By using direct memory access DMA
What is Direct Memory Access (DMA)? Provide an example of accessing data on a hard drive using a DMA.
A method that allows peripheral devices to transfer data directly and from the system’s memory without involving the CPU
- CPU tells DMA what block of data it wants to read (command + start address + size of block it wants in DMA registers)
- DMA configures the I/O device controller for every data that must be read.
- Device controller accesses the hard drive.
- Hard drive recovers data and writes it in the device controller buffer.
- DMA reads data in device controller and copies it in memory.
- Once all the data is transferred into memory, DMA tells CPU the I/O transfer is completed using an interrupt.
How does the CPU interface with the device to coordinate the transfer for DMA?
CPU initiates a DMA operation by writing values into special registers that can be independently accessed by the device.
Device initiates corresponding operation once it receives the command from the CPU.
CPU Is allowed to execute other programs while the DMA controller is transferring data. Does this process interfere with the execution of user programs? If so, how?
Both device and CPU can be accessing memory simultaneously. A CPU might therefore have to compete with the device to access the memory, lowering its speed.
What are the advantages of DMA? What are some issues regarding to DMA?
Less operations executed by CPU. Less interrupts to treat. CPU can execute other useful code in parallel.
Deciding what to execute while waiting for I/O operation. Providing code to configure hardware devices, treat interrupts. Ensuring program state remains consistent through switches.
Describe three general methods for passing parameters to the operating systems.
- Passing parameters in registers.
- Registers pass starting addresses of blocks of parameters.
- Parameters can be placed, or pushed, onto the stack by the program, and popped off the stack by the OS.
Provide an example of system components that are difficult to layer?
The virtual memory subsystem and the storage subsystem are typically tightly coupled and requires careful design in a layered system due to the following interactions. Many systems allow files to be mapped into the virtual memory space of an executing process. On the other hand, the virtual memory subsystem typically uses the storage system to provide the backing store for pages that do not currently reside in memory. Also, updates to the file system are sometimes buffered in physical memory before it is flushed to disk, thereby requiring careful coordination of the usage of memory between the virtual memory subsystem and the file system.
What are some of the specific functionalities of the OS as an intermediary between users/applications and computer hardware?
Providing a level of abstraction that hides the details of hardware architecture from applications.
Manages sharing of HW resources among applications and users.
Optimises performance through resource management.
What would application developers have to know without operating systems? What effects would this have?
Hardware platform details to be able to write applications.
Managing memory and address space.
Manage I/O operations.
Manage communications.
Manage file system.
Time consuming, error prone application development. Low portability, as code cannot be easily used on other HW platforms. Hard to use third-party code and libraries.
What is a driver?
A software development that allows the operating system to communicate with and control hardware devicesm providing a standardised interface for device functionality
What are the 8 main responsibilities of an operating system?
- Process Management:
- creating and deleting, scheduling, suspending, resuming, synchronising, inter-process communication - Memory Management:
- allocating, deallocating memory space; efficient utilisation of memory; kepping track of current memory use and by whom - I/O Management:
- buffer-caching system, general device-driver interface, drivers for specific HW devices - File Management:
- mainpulating files, directories; maping files onto secondary storage-disks; free space management and storage allocation; disk scheduling - Protection:
- ensuring that concurrent processes do not interfere with one another - Error Detection:
- debugging facilities - Security:
- against other processes, outsiders - Accounting:
- using timers, CPU Cycles, main memory usage, I/O device usage
What is an interrupt service routine?
A specialised function or routine in software that is executed in response to an interrupt, handling the interrupt cause and ensuring the CPU can resume its normal operations afterward
What is an interrupt vector table?
A data structure that holds the addresses of interrupt service routines (ISRs), allowing the CPU to quickly locate and execute the appropriate ISR when an interrupt occurs
Describe an example of a HW device instructing the OS to carry out an operation.
- Interrupt generated to notify the CPU of something.
- OS jumps at predefined address memory corresponding to this interrupt.
- OS saves current execution context.
- OS checks what caused interrupt.
- OS retrieves the address of corresponding interrupt service routine from interrupt vector table.
- OS executes the interrupt service routine.
- OS resumes execution context.
What are traps/exceptions? For what purposes can they be used?
Software-generated interrupts caused by either a software error or by calling a specific assembly function
Calling operating system routines or catching errors
What is the trap handler?
A routine in the operating system that handles exceptional conditions or events that interrupt the normal execution of a program
Describe an example of an application generating a trap and the consequent operations.
1.Application generates trap
2. CPU jumps at predefined address in memory corresponding to the trap handler
3. OS saves current execution context
4. OS checks why the trap was generated
5. OS executes the requested service
6. OS resumes the execution context
What is the OS Dual-Mode Operation? What is the user-mode? How about the kernel mode? Which operations are executed in which mode?
What is the advantge of this Dual-Mode?
A system architecture that allows the CPU to operate in two modes, user and kernel.
Where application run with limited access to system resources.
Where the operating system has full control over hardware and system operations.
Most instructions executed in user mode, but some privileged instructions are only executable in kernel mode, such as accessing memory locations reserved for the OS.
Allows the OS to protect itself and other syste components
What is the microkernel approach to system design?
Reduces the kernel to only the core functionalities necessary for basic system operation, such as interprocess communication (IPC), basic scheduling, and low-level hardware management
Higher-level services, like file systems, device drivers, and network protocols, are implemented in user space as separate processes, enhancing modularity and fault isolation
What are the main advantages of the microkernel approach to system design? How about the primary disadvantages?
Advantages:
Adding a new service does not require modifying the kernel
More secure as more operations are done in user mode than kernel mode
Simpler kernel design and functionality typically result in a more reliable OS
Disadvantages:
Overheads associated with interprocess communication (between kernel and user services);
Frequent use of OS’s messaging functions
What is the mode bit? How is the mode bit changed?
A bit in the CPU’s status register that indicates the current operating mode (user or kernel mode)
A system call changes the execution mode to kernel mode, while returning from the system call resets the mode to user.
What are the six main motivations for operating systems?
- Dealing with diverse CPUs and architectures, organisations.
- Transparency, i.e., hiding certain details
- e.g., location of data in physical memory, physical memory size, processor architecture - Visualisation, i.e., providing a simple, abstract, logical model of system with virtual memory, CPU, disk
- allows programs to be developed as if they were the sole user of the HW resources - Support for Shared Functionality:
- well defined abstractions of concepts, providing system calls - Portability:
- programs written within an OS or API can compile/run on any system supporting that OS/API
- OS provides a unified machine view, defining a virtual machine - Support for Concurrency:
- concurrency transparency, where each task essentially has a virtual machine of its own
- manages and protects tasks from each other
- ensures efficiency through scheduling
What are system calls? How are they usually available?
Programming interface to the services provided by the OS, typically written in a high-level language
Through a high-level Application Programming Interface (API)
What is an Application Programming Interface?
A set of rules and protocols that allow different software applications to communicate with each other and with the operating system
What are the five main types of System Calls?
Process management, File management, Memory management, Device manamgement, Communications, Miscellaneous
What are the three advantages of an API over system calls? What is a disadvantage?
works at higher abstraction level, closer to programs’ needs
may combine many system calls to implement higher level tasks
programs using an API can compile/run on any system supporting the API
adds one more layer, with additional overhead
What are two different flavours of operating systems?
Real-time OS and Embedded OS
What is real-time OS?
OS designed to process data and respond to inputs within a guaranteed time frame, ensuring that critical tasks are completed within strict timing constraints
known performance, known bounds on maximum latencies of API calls
real-time control, stringent dependability
What is embedded OS?
specialised OS designed to run on embedded systems - dedicated devices with specific functions, offering optimised performance, low resource usage, and real-time capabilities
small footprint, low system requirements
What is a process?
A program in execution, with a context of execution, which owns resources, i.e., has memory and can own other resources such as files
Can several processes run the same program?
Yes
Would several processes running the same program have the same contexts of execution?
No
What is a thread? What is shared among threads? What is not shared among threads?
A dispatchable unit of work within a process
Code, data, files
Registers, stack
What five things is a process defined by?
- Program code
- Stack - region of memory used to store function calls, local variables, control information
- Heap - region of memory used for dynamic memory allocation, where memory is allocated and freed at runtime
- Data - global variables whose size are unknown
- Current state of execution
What are the five process states?
- New - process being created
- Ready - process waiting to be assigned to a CPU
- Running - process instructions are being executed
- Waiting - process is waiting for some event to occur
- Terminated - process has finished executing
Where are the local variables of a process stored?
in the stack
What does a process control block (PCB) do? List the things that the PCB keeps track of.
Records information associated with a process’ context of execution
Process state;
Program Counter (location of next instruction to execute);
CPU registers (contents of all process-centric registers);
CPU scheduling information (priorities, scheduling queue pointers);
Memory-mangement Information (memory allocated to the process);
Accounting information - CPU used, clock time elapsed since start, time limits;
I/O status information - I/O devices allocated to process, list of open files
What is a context switch?
The saving of the state of a process whose execution is to be suspended, and the reloading of this state when the process is to be resumed
How are processes created? How are processes generally identified? Can parent processes share their memory or resources with their children processes?
Parent processes create children processes, which in turn create other processes, forming a tree of processes.
Through a process identifier (pid)
Yes
What are the three resource sharing options, two execution options, and two address space options?
Parent and children share all resources. Children share subset of parent’s resources. Parent and child share no resources.
Parent and children execute concurrently. Parent waits until children terminate.
Child is a copy of the parent. Child has a new program loaded into its address space.
What is the Portable Operating System Interface (POSIX)? What four things does it provide?
set of standards defining a consistent application programming interface (API) for maintaining compatibility between different Unix-like operating systems
- Host language, compiler (C)
- Programming Interface Definition FIles
- Programming Interface Implementation Binary or Code
- Run-time System (OS)
How can an identicaly copy of a process be created (i.e., a child)? What is the sole thing that varies between the two processes? What is shared between the parent and child?
By the parent calling the fork() operation
The return value of the fork() operation: 0 for the child, child-pid for the parent
Address space (variables, memory, file descriptors), program counter (next instruction to execute), process state (open files, signal handlers, etc)
What is execlp()?
An instruction that overwrites the calling process with its argument (an executable program), meaning that the code following it is never reached
What is perror()?
A generic error printing routing
How are the child and parent independent?
Child can execute different code/instructions, close or modify resources independently, terminate independently of parent process
What does exit(status) do? How about wait()? What does wait return? How about waitpid()?
Terminates the process
Blocks until one of children exit
PID of terminated child
Blocks until a specific child (specified in argument) changes its state
What is blocking wait? How can it be done?
Parent waits for child to terminate, blocking until child finishes
through wait()
What is polling wait? How can it be done?
Parent checks periodically if the child has terminated without blocking, allowing it to perform other tasks in between checks
waitpid(child, &status, WNOHANG), which checks if the specified child process has terminated, but does not block
WNOHANG flag makes the call non-blocking, so the parent can perform other activities between checks, such as executing code or handling multiple tasks
How can process be terminated?
Processes can terminate themselves through exit(), with exit() returning status value from child to parent if parent was waiting.
Alternatively, parent may terminate execution of children processes through abort/kill
What is cascading termination?
The child being terminated automatically because the parent was.
What is a zombie?
A child process that has no parent waiting upon its termination, i.e., that invoked wait()
What is an orphan?
A child process that had its parent terminated without having invoked wait()
What are two models for interprocess communication?
Message Passing and Shared Memory
What is message passing? Are messages blocking or non-blocking? What is rendez-vous communication in the context of message passing? How can asynchronous communication be carried out? What can happen when the buffer is full? What happens if the producer is not blocked and the buffer is full?
Producer process sends a message to the kernel, which then forwards the message to the target process
Can be both
Where both the sending and receiving are blocking, and communicating processes synchronise on the transmission
Through the use of a temporary queue or buffer being used to hold items temporarily
The producer may be blocked
Consumers see most recent data, miss old one
What is shared memory?
Processes share a portion of their address space, so messages can be passed through this shared memory.
Similarities between iOS and Android? Differences?
Similarities:
Based on existing kernels (Linux, Mac OS X);
Architectures use software stacks;
Provide frameworks for developers
Differences:
iOS closed-source, Android open-source;
iOS developed in Objective-C, Android in Java;
Android uses virtual machine, iOS executes code natively
Is the DMA a software or hardware component? Is the DMA part of the operating system? Does the DMA replace I/O controllers?
Hardware
No, it is not.
No, it does not.
Could a DMA negatively impact the execution time of a program?
Yes
What mode is a CPU in after an interrupt?
Kernel mode
Through what mechanism are system calls implemented?
Traps
Explain the different steps involved in the execution of a system call
Process puts the code of the sys call in a register.
It generates a trap that switches the
execution mode from user mode to kernel mode.
The kernel executes the right system call using the
system call code. \
The kernel restores the mode bit so that the execution resumes in user mode.
What is synchronisation?
The limitation of possible program traces by coordinating execution such that certain conditions are satisfied.
E.g., certain invariant is satisfied and/or execution has some desired property
What is an invariant?
an assertion that holds at all control points, such as mutual exclusion being maintained or y being less than or equal to x
What does action synchronisation rely on?
Action counting and invariants on the counting
If A is an action in a program, what does cA denote?
The number of completed executions of A
What is a topology invariant?
An invariant derived directly from the program text
E.g., two actions always occuring one after the other
What two things is action synchronisation specified by? What are such inequalities referred to as?
Inequalities on:
- Action counts
- Program variables directly related to this counting
Synchronisation conditions or synchronisation invariants
What does P(s) refer to? How about V(s)?
P(s): <await(s>0)>; s=s-1;
V(s): <s = s + 1>
What are the primary two semaphore invariants? What invariant arises from these two?
S0: S >= 0
S1: s = s0 + cV(s) - cP(s)
S2: cP(s) <= s0 + cV(s)
What is the progress property of semaphores?
Blocking is only allowed if the safety properties would be violated
What is the action synchronisation solution in general? Specifically, give a collections of tasks/threads executing actions A,B,C,D and the synchronisation:
SYNC: a * cA + c * cC <= b * cB + d * cD + e for non-negative constants a,b,c,d,e
Introduce a semaphore s, s0 = e and replace:
A -> P(s)^a; A
C -> P(s)^c; C
B -> B; V(s)^b
D -> D; V(s)^d
What does sem_t *sem declare?
A pointer to a semaphore object, which will be used for synchronization.
What function is used to open and create a named semaphore?
sem_open(name, flags, mode, init-val)
In sem_open, what does the name parameter represent? What does the flags parameter in sem_open determine? What is the purpose of the mode parameter in sem_open? What does the init-val parameter in sem_open define?
A system-wide unique name for the semaphore.
The operation to be performed.
To specify the file permissions.
The initial value of the semaphore.
What function is used to close a semaphore in the current process while keeping it accessible to others?
sem_close(sem)
Which function removes a named semaphore from the system? When is a named semaphore fully removed from the system?
sem_unlink(name)
When no process is using it.
What does sem_init(sem, pshared, init-val) do? In sem_init, what does the pshared parameter indicate?
Initializes an unnamed semaphore.
Whether the semaphore is shared across processes or just threads within a process.
What function is used to destroy an unnamed semaphore? What happens if you use a semaphore after it has been destroyed with sem_destroy?
sem_destroy(sem)
It must not be used, as its resources are released.
What does sem_wait(sem) do?
Attempts to decrement (lock) the semaphore; if the semaphore value is greater than zero, it decrements it. If the value is zero, it blocks until the semaphore becomes available.
How does sem_trywait(sem) differ from sem_wait(sem)?
sem_trywait does not block; it attempts to decrement/lock the semaphore and returns an error if not possible.
What is the purpose of sem_post(sem)?
To increment the semaphore and wake one waiting thread if any are blocked.
How can you retrieve the current value of a semaphore? In sem_getvalue, what does a negative semaphore value represent?
By using sem_getvalue(sem, &val).
The number of waiters (the length of the waiting queue).
When is busy-waiting accepted? What is the condition for busy-waiting to work as expected?
When:
- Waiting is guaranteed to be short in comparison to the cost of context switching
- There is nothing else to do
The tests in the while and locking the mutex are executed atomically
What is a deadlock state? How is it typically proven that a deadlock does NOT exist?
A system state in which a set of tasks is blocked indefinitely
Proof by contradiction; Assume deadlock occurs, investigate all task sets that can be blocked at the same time, show a contradiction;
What are the three main ways of preventing deadlocks?
Always let critical sections terminate
- always call unlock(m) after lock(m)
Avoid cyclic waiting
- avoid P or lock operations that may block indefinitely between lock(m) and unlock(m)
- use a fixed order when calling P-operations on semaphores or mutexes
Avoid greedy consumers
- P(a)k should be an indivisible atomic operation when tasks compete for limited resources