Operating Systems Flashcards
What is a program?
Compiled code that can run on the OS
What is a task in OS and microcontrollers?
Basic unit of programming which an OS controls. Depending on the OS, a task may be each program or each process within a program
What is a thread?
Basic unit of CPU utilization. At most basic consists of a program counter, stack, set of registers and a thread id.
What is a context switch in OS?
Act of storing the state of a thread or process, so said thread or process can be resumed at a later date.
What is pre-emptive multitasking?
The use of interrupts and a scheduler to determine which process should execute next. It is a common multitasking technique, where the OS allocates different amounts of time for a process based on its priority.
What is cooperative multitasking?
Also non as non-preemptive multitasking at times.the OS provides the appearance of simultaneous execution by rapidly switching between tasks
What is blocking in operating systems?
Blocking refers to processes that are waiting for a specific event or resources to become available. These processes are timeout protected.
Define priority in Operating systems
The level of importance of a task. Multiple tasks can have the same priority.
What is a scheduler in operating systems?
A scheduler is a software that handles task scheduling. i.e. the order in which tasks are exectuted.
Define Timers in Operating Systems
The main task of a timer is to interrupt the CPU after a specific period of time. Used to generate ticks at precise intervals. Must count continuously.
Define Interrupts in Operating Systems
Signals sent to the CPU to stop the current task and to accordingly create an alternate portion of the OS to deal with the signal.
What is an operating system?
Software that manages computer hardware resources
It is used to provide common services for programs,
Many applications cannot run without it.
Describe the system hierarchy
At the top of the hierarchy is the user who only interacts with the application. The application interacts with the OS and user but does not interact with the hardware. The OS interacts with the application and the Hardware. The Hardware only interacts with the OS.

What are the common types of Operating System?
Multi-user
Multi-tasking
Distributed
Embedded
Templated
Real Time
Features of a multi-user operating system
Multiple Users can share the same system, used by time-sharing systems/servers. For each user appears as if they have sole control over the system.
Features of a Multi-tasking Operating System
Allows multiple programs to execute simultaneously
Uses pre-emptive or cooperative multitasking
Has Slotted behaviour
Features of a Distributed Operating System
Allows for management of a group of computers as one
Can spread distributed computations across multiple machines
Features of a Templated Operating System
Single ‘virtual machine’ acts as a guest of the operating system
Used in virtualisation and cloud computing
Features of an Embedded Operating System
Used on embedded computer systems
Can operate with limited resources
Compact and efficiency
Features of a Real-Time Operating System
Specialised scheduling algorithms
Deterministic behaviour
Quick, predictable response to events
What is the kernel?
The lowest level of the operating system
Manages I/O requests from software
Translates them into data processing instructions for the CPU/other components
What is the difference between kernel mode and user mode programs?
Kernel Mode has access to each resource in the operating system
User-mode programs are in turn restricted in their access
Differences betwen Kernel Mode and User Mode drivers
In kernel mode, the lack of restrictions means the driver may overwrite resources used by other programs.
However, with user-mode programs, this cannot happen.
User-mode drivers allow for immediate restarts of the driver when required, not possible with kernel mode drivers
Define the Operating System Shell
This is the user interface for an operating system, it is often graphical and is a task in itself.It interfaces with the kernel.
What are some of the common features of Modern Desktop Operating Systems
Modern Operating Systems are more reliable, this is because ‘unreliable’ interfaces can run in user mode and normally implement preemptive multitasking.
Rare Failures for modern systems are:
Hardware Failure
CPU stuck in device driver
Fatal exception in device driver/kernel
What is virtual memory?
Virtual memory can be defined as a technique that uses main memory as a ‘cache’ for secondary storage.
Or a feature of an OS, which allows the system to compensate for shortages in physical memory by temporarily transferring pages of data from RAM to disk storage.
It allows a program to access memory via a virtual address
What are the benefits of a ‘virtual’ address?
A virtual address can be translated into a physical address and is used to access main memory.
It allows for efficient sharing of memory between programs, although one must keep in mind how this is structured.
It removes the programming burdens of limited memory
What is a page
A page is a contiguous block of virtual memory,
contiguous meaning solid block of data.
What is a page fault
A page fault is when an accessed page is not found in the main memory.
This means the page must be retrieved from the disk which is more than 1000x slower than retrieving from main memory. This severely slows down program execution speed.
What is a super loop/embedded loop?
A super loop is an alternative to OS. It is simply a loop in which other tasks are run. The loop is not meant to end.
Features of Super loops
Simple, easy to build, debug, test and maintain
Efficient as minimal hardware requirement
Highly portable, can easily be implemented on many kinds of devices.
However, Not accurate/ flexible enough for precision timing.
Operates at full power at all times, the device never sleeps.
How can programs be designed for time-constraints
Delays can be used to run a program at specific times, however, this approach is flawed as it requires precise knowledge of how long a task takes and for said task o never vary in execution time.
Alternatively, hardware timers can be used to generate interrupts. As long as the timer counts continuously the program can be designed to generate ticks at precise intervals.
For timers, what is a tick?
A tick is an arbitrary unit for measuring internal system time. What exactly is a tick varies based on the OS and may vary by installation.

-Super User
What does the rate of tick generation depend on?
The rate of tick generation depends on the crystal frequency and the counter configuration
How can software reduce power consumption?
This can be achieved by putting the system to a kind of sleep. Here interrupts can be used to wake the system up at next processor overflow.
What states can tasks be in?
Running- actually using the processor
Ready- Able to run but a higher priority task is currently running
Blocked- waiting for an external event or time, but is timeout protected
Suspended - Not available for scheduling and is not timeout protected

How does multitasking support the OS?
Multitasking and intertask communication allow for complex applications to be partitioned into smaller, more manageable tasks.
This makes software testing easier as well as work breakdown between teams and code reuse.
It means that timing and sequencing details can be removed from the application code and laid into the hands of the OS.
Why use context switching
Context switching is used as tasks do not have an awareness of when they are suspended, so the OS saves the context of the system to be restored via the kernel near execution time. This increases performance as it means that higher priority tasks can be run when ready and allow for scheduling.
What is a scheduling policy?
It is an algorithm that a scheduler uses to determine which task to execute at a particular time
What are the benefits of RTOS?
Task Scheduling: Tasks are called when needed, ensuring better program flow and event response times
Multitasking:. Task scheduling gives the illusion of multiple simultaneous task executions
Deterministic Behaviour: Events and interrupts led are handled within a defined time
Shorter ISRs: enables more deterministic interrupt behaviour
InterTask Communication: manages sharing of data, memory and hardware resources between multiple tasks
System Management: Allows focusing on app development rather than resource management
Defined Stack Usage: Each task has a defined stack space allowing for predictable memory usage.
What are the limitations of RTOSs?
Unlike desktop Os, programs cannot be loaded after compilation or easily exchange components.
The entire system must be completed together at compile-time, whilst this is efficient as optimisation is applied on the entire program, this is also restrictive as any changes require a firmware update.
What are the RTOS timing categories?
Strict Timing: Events must happen on a strict schedule e.g. every 10ms
Flexible timing: Wide range of acceptable times
Deadline only timing:Only Upper Limit is specified
What is the RTOS scheduling policy?
Ensure that the highest priority task that is able to execute is the task given processing time.
Results of the RTOS scheduling policy
This means processing time may have to be shared, ‘fairly’ between tasks of equal priority if the tasks are able to run simultaneously.
What are the features of a sleeping task and a blocked task in RTOS?
When sleeping the task specifies the wake time
When blocked, the task specifies the maximum wait time.
How does the RTOS measure time?
The RTOS measures time using a tick ‘count’ variable, a tick is implemented using timer interrupts, the resolution of a tick is dependent on the interrupt frequency.
At each tick the kernel checks whether to unblock/wake tasks
For RTOS, what happens when tasks are sleeping
When sleeping a task gives up its access to the CPU. It specifies its wake time.
For RTOS, what happens when tasks are blocked?
When blocked a task specifies its maximum wait time.
Describe Task Priority
Each task as a priority
The idle task has a priority of zero
Low priority numbers are for low priority tasks
What is the relationship between tasks and the scheduler?
Tasks have no knowledge of the scheduler
Whilst the scheduler’s job is to ensure the context around a task is saved whilst the task may be blocked, suspended etc.
What are the benefits and flaws due to separate stacks for each task?
Benefits: Simple, no restriction on use, supports full preemption, fully prioritised
Flaws: High usage from individual stacks, restrictions on re-entrancy are required, i.e. on subroutines calling themselves.
Describe the Idle Task
The Idle task runs at lowest priority, it is used to clean up resources allocated by the kernel to deleted tasks
It can call a ‘hook’ function when no higher priority tasks are available
Hook function puts the processor into low power mode
Steps for RTOS context switch
- TaskA is executing, TaskB previously suspended, so context already saved on TaskB stack.
- RTOS ‘tick’ occurs as TaskA is about to execute LDI. When tick occurs, places PC on stack before jumping to the RTOS tick ISR
- To save context, pushes context of processor onto TaskA stack. Kernel stores copy of stack pointer for each task
- After context has been saved, increments tick count.
In this example, incremented tick count means that TaskB is now ready to run.
TaskB has a higher priority than TaskA, so kernel selects TaskB to be given processor time. - Task B stack pointer is
retrieved. - Restores TaskB context from the stack into the processor registers
- The stack pointer was adjusted to point to TaskB’s stack, Program Counter restored for TaskB.
So, when e.g. returning from interrupt, executes next TaskB instruction

What is free RTOS?
Ported to at least 34 Processors
Open Source free software for rtos system
Features of RTLinux
Linux kernel operates as a thread
Interrupts for deterministic processing are processed by the real-time core; other
interrupts forwarded to Linux (running at a lower priority)
Linux drivers handle general I/O
Can use FIFO to transfer between OS and RTLinux
Example capabilities (on x86 hardware):
15 µs to begin an ISR after an interrupt event
Periodic tasks run within 25 µs of schedule
Compared against ‘standard’ Linux
Up to millisecond level scheduling precision
•Not designed for guaranteed timing
WHat is RTLinux
RTLinux : modified Linux kernel
Adds hard real time capabilities to ‘standard’ Linux OS
Runs whole Linux OS as fully pre emptive process
Can use for real time control
Capability of running real time tasks and interrupt handlers: execute regardless of
Linux OS operations
http://
Linux Kernel Vs RTLinux Kernel
Linux drivers handle general I/O
Can use FIFO to transfer between OS and RTLinux
Example capabilities (on x86 hardware):
15 µs to begin an ISR after an interrupt event
Periodic tasks run within 25 µs of schedule
Compared against ‘standard’ Linux
Up to millisecond level scheduling precision
Not designed for guaranteed timing

Describe the operation of RTLinux
Linux kernel operates as a thread
Interrupts for deterministic processing are processed by the real time core; other
interrupts forwarded to Linux (running at a lower priority)

How are periodic tasks implemented via timer interrupts
The timed interrupt is declared early on in the program. The task is executed using functions called from the ISR
What does ISR stand for?
Interrupt Service Routine
What is strict timing
Events must happen on a strict schedule e.g. every 15ms.
What is flexible Timing
Events have a wide range of Acceptable times
What is deadline only timing?
Only the upper limit of event duration is specified.
RTOS Context Switch Step One
TaskA is executing
TaskB previously suspended, so context already saved on TaskB stack

RTOS Context Switch Step Two
RTOS ‘tick’ occurs as TaskA is about to execute LDI
When tick occurs, places PC on stack before jumping to the RTOS tick ISR

RTOS Context Switch Three
To save context,
pushes context of
processor onto TaskA
stack
Kernel stores copy of
stack pointer for each
task

RTOS Context Switch Step 4
After context has been saved, increments tick count
In this example, incremented tick count means that TaskB is now ready to run
TaskB has higher priority than TaskA , so kernel selects TaskB to be given
processor time
RTOS Context Switch Step 5
Task B stack pointer is
retrieved

RTOS Context Switch Step 6
Restores TaskB context from the stack into the processor registers

RTOS Context Switch Step Seven
Stack pointer was adjusted to point to TaskB’s stack, Program Counter restored for TaskB
So, when e.g. returning from the interrupt, executes next TaskB instruction
