REAL TIME OPERATING SYSTEM (RTOS) – COMPLETE NOTES
(For Embedded Systems Jobs & Viva)
1. What is RTOS?
RTOS (Real-Time Operating System) is an operating system that responds to
inputs within a fixed time limit.
Simple Definition
• RTOS ensures correct result + correct time
• Time is more important than speed
Example
• Airbag system
• Medical ventilator
• Traffic signal controller
If response is late → system failure
2. Why RTOS is used in Embedded Systems?
• To handle multiple tasks
• To meet timing deadlines
• To improve system reliability
• To manage CPU, memory, and peripherals
3. Types of Operating Systems (Comparison)
Parameter GPOS RTOS
Full form General Purpose OS Real-Time OS
Time guarantee No Yes
Deadline Not important Very important
Examples Windows, Linux FreeRTOS, VxWorks
1
Parameter GPOS RTOS
Usage PC, Mobile Embedded systems
4. Types of RTOS
4.1 Hard Real-Time RTOS
• Missing deadline = system failure
• Used in critical systems
Examples:
Airbags, Missile systems
4.2 Firm Real-Time RTOS
• Missing deadline = result becomes useless
• No complete failure
Examples:
Industrial robots
4.3 Soft Real-Time RTOS
• Missing deadline = performance degrades
• Used in multimedia
Examples:
Audio/video streaming
Comparison of RTOS Types
Parameter Hard RTOS Firm RTOS Soft RTOS
Deadline miss Not allowed Rare Allowed
Risk Very high Medium Low
Usage Safety systems Industrial Multimedia
2
Parameter Hard RTOS Firm RTOS Soft RTOS
Cost High Medium Low
Examples Airbag Robot Music player
5. Task / Thread
A task is a small program running under RTOS.
Task Characteristics
• Has its own stack
• Has priority
• Has state
6. Task States
1. Running – Task is executing
2. Ready – Waiting for CPU
3. Blocked – Waiting for event
4. Suspended – Stopped manually
7. Scheduler
Scheduler decides which task runs next.
Functions
• Selects task based on priority
• Switches between tasks
8. Scheduling Algorithms
8.1 Preemptive Scheduling
• High priority task interrupts low priority task
• Used in most RTOS
3
8.2 Cooperative Scheduling
• Task releases CPU by itself
• Less responsive
Comparison: Preemptive vs Cooperative
Parameter Preemptive Cooperative
Task switch Automatic Manual
Response time Fast Slow
Complexity High Low
Usage RTOS Simple systems
Safety Better Less
9. Context Switching
Saving current task state and loading next task state.
What is saved?
• Program Counter
• Registers
• Stack Pointer
10. Interrupts
Interrupt is a signal that stops CPU temporarily.
Types
• Hardware interrupt
• Software interrupt
11. ISR (Interrupt Service Routine)
ISR is the code executed when interrupt occurs.
4
Rules of ISR
• Very short
• No blocking calls
• Should be fast
12. Task Priority
• RTOS runs highest priority task first
• Priority can be static or dynamic
13. Priority Inversion
Low priority task blocks high priority task.
Solution
• Priority inheritance
• Priority ceiling
14. Inter-Task Communication (IPC)
Used to share data safely between tasks.
15. Semaphore
Semaphore is a signaling mechanism.
Types
1. Binary Semaphore
2. Counting Semaphore
Binary vs Counting Semaphore
Parameter Binary Counting
Values 0 or 1 0 to N
5
Parameter Binary Counting
Usage Event signal Resource count
Complexity Low Medium
Example Button press Buffer
Speed Fast Slight slow
16. Mutex (Mutual Exclusion)
Used to protect shared resources.
Features
• Ownership
• Priority inheritance
• Prevents race condition
Semaphore vs Mutex
Parameter Semaphore Mutex
Ownership No Yes
Priority inheritance
Usage Signaling Resource protection
Deadlock safety Less Better
Common use Events Shared data
17. Message Queue
Used to send data between tasks.
Features
• FIFO based
• Safe communication
6
• Fixed size messages
18. Mailbox
• Similar to message queue
• Usually one message at a time
19. Event Flags
• Used to signal multiple events
• Task waits for specific flag
20. Software Timers
Used to execute function after a time delay.
Types
• One-shot timer
• Periodic timer
21. Memory Management in RTOS
Types
1. Static allocation
2. Dynamic allocation
Static vs Dynamic Memory
Parameter Static Dynamic
Allocation Compile time Run time
Fragmentation No Yes
Speed Fast Slower
7
Parameter Static Dynamic
Safety High Medium
RTOS use Preferred Limited
22. Deadlock
Tasks waiting forever for resources.
Conditions
• Mutual exclusion
• Hold and wait
• No preemption
• Circular wait
23. Watchdog Timer
Resets system if software hangs.
24. Power Management in RTOS
• Tickless idle
• Sleep modes
• Low power states
25. RTOS Kernel
Core of RTOS that manages:
• Tasks
• Scheduler
• IPC
• Memory
8
26. Popular RTOS Used in Industry
• FreeRTOS
• VxWorks
• µC/OS-II / µC/OS-III
• Zephyr
• ThreadX
27. RTOS vs Bare Metal
Parameter RTOS Bare Metal
Multitasking Yes No
Complexity High Low
Timing control Better Manual
Scalability High Low
Usage Complex systems Simple systems
28. RTOS Interview Viva – One Line Answers
• RTOS ensures deterministic response
• Scheduler selects task based on priority
• Mutex prevents race condition
• Semaphore is used for signaling
• ISR must be short and fast