RTOS Interview questions
If you're interviewing for an Embedded Software, Automotive ECU, AUTOSAR, or RTOS developer role (3–15 years experience), these are among the most frequently asked RTOS interview questions.
1. RTOS Basics
Q1. What is an RTOS?
Answer:
An RTOS (Real-Time Operating System) is an operating system designed to provide deterministic and predictable response times. It ensures that critical tasks execute within their required deadlines.
Q2. Difference between RTOS and General Purpose OS?
| RTOS | General OS |
|---|---|
| Deterministic | Best effort |
| Low latency | Higher latency |
| Predictable scheduling | Fair scheduling |
| Used in embedded systems | Used in PCs/Mobiles |
Q3. Types of RTOS?
- Hard RTOS
- Firm RTOS
- Soft RTOS
Example:
- Airbag → Hard
- ABS → Hard
- Multimedia → Soft
Q4. What is deterministic behavior?
The ability of the OS to guarantee maximum response time.
Example:
Interrupt serviced within 20 µs every time.
2. Tasks
Q5. What is a Task?
A task is an independently scheduled execution unit (similar to a thread).
Q6. Difference between Process and Task?
| Process | Task |
|---|---|
| Own memory | Shared memory |
| Heavyweight | Lightweight |
| Separate address space | Same address space |
Q7. Task States?
Running Ready Blocked Suspended Terminated
Diagram:
Ready | Running / \ Blocked Suspended
Q8. Difference between Ready and Blocked?
Ready
- Waiting for CPU
Blocked
- Waiting for Event
- Waiting for Semaphore
- Waiting for Queue
3. Scheduling
Q9. What is Scheduling?
Selecting which task runs next.
Q10. Scheduling Algorithms?
- Fixed Priority Preemptive
- Round Robin
- Cooperative
- EDF
- RMS
Q11. Which scheduling does OSEK use?
Fixed Priority Preemptive.
Q12. What is Preemption?
A higher-priority task interrupts a lower-priority task.
Q13. What is Context Switching?
Saving one task's context and restoring another's.
Saved information:
- PC
- SP
- Registers
- PSW
Q14. When does Context Switch occur?
- Interrupt
- Task delay
- Semaphore
- Queue
- Higher priority task becomes Ready
Q15. Context Switching overhead?
- CPU cycles
- Stack usage
- Cache effects
4. Priority
Q16. What is Priority Inversion?
Low-priority task blocks a high-priority task because it holds a shared resource.
Q17. How to solve Priority Inversion?
- Priority Ceiling Protocol (PCP)
- Priority Inheritance Protocol (PIP)
Q18. Explain PCP.
(As discussed earlier.)
Q19. Explain PIP.
Low-priority task temporarily inherits the waiting high-priority task's priority until it releases the resource.
5. Synchronization
Q20. What is a Critical Section?
Code accessing shared resources that must not be interrupted.
Q21. What is a Mutex?
Used for mutual exclusion to protect shared resources.
Q22. Difference between Mutex and Semaphore?
| Mutex | Semaphore |
|---|---|
| Ownership | No ownership |
| Binary | Binary or Counting |
| Resource protection | Signaling or resource management |
Q23. Binary Semaphore vs Counting Semaphore?
Binary
- 0 or 1
Counting
- Multiple available resources
Q24. Spinlock vs Mutex?
Spinlock
- Busy waiting
- Very short critical sections
Mutex
- Task sleeps while waiting
- Longer critical sections
6. Inter-Task Communication (IPC)
Q25. IPC mechanisms?
- Queue
- Semaphore
- Mutex
- Event
- Mailbox
- Shared Memory
- Message Buffer
Q26. Queue vs Mailbox?
Queue
- Multiple messages
Mailbox
- Often single/latest message
Q27. Shared Memory advantages?
Fastest IPC, but requires synchronization.
7. Interrupts
Q28. What is ISR?
Interrupt Service Routine.
Q29. ISR vs Task?
| ISR | Task |
|---|---|
| Immediate | Scheduled |
| Short | Longer execution |
| No blocking | Can block |
Q30. Top Half and Bottom Half?
Top Half
- Minimal ISR work
Bottom Half
- Deferred processing in a task
Q31. Why keep ISR short?
To reduce interrupt latency and improve responsiveness.
8. Memory
Q32. Stack vs Heap?
| Stack | Heap |
|---|---|
| Automatic | Dynamic |
| Faster | Slower |
| Deterministic | May fragment |
Q33. Why avoid malloc() in RTOS?
- Fragmentation
- Non-deterministic allocation time
Q34. Stack Overflow detection?
- Watermarking
- Guard patterns
- MPU protection
- Stack overflow hooks
9. Timers
Q35. Software Timer vs Hardware Timer?
Software
- Managed by RTOS
Hardware
- Physical timer peripheral
Q36. Periodic vs One-shot timer?
Periodic
1s 2s 3s
One-shot
Runs only once.
10. Deadlock
Q37. What is Deadlock?
Two or more tasks wait forever for each other.
Q38. Conditions for Deadlock?
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
Q39. Deadlock Prevention?
- Lock ordering
- Timeouts
- Avoid nested locks
- PCP
11. OSEK/AUTOSAR OS
Q40. Basic Task vs Extended Task?
Basic
- No WaitEvent()
Extended
- Supports WaitEvent()
Q41. Category 1 vs Category 2 ISR?
Category 1
- No OS services
Category 2
- Can call OS APIs
Q42. Alarm vs Counter?
Counter
- Counts ticks
Alarm
- Triggers action after counter reaches a value
Q43. Event in OSEK?
Synchronization mechanism for Extended Tasks.
12. Real-Time Concepts
Q44. Latency?
Delay between event occurrence and response.
Q45. Jitter?
Variation in execution timing.
Example:
Expected:
10 20 30 40
Actual:
10 22 29 43
Q46. Throughput vs Latency?
Throughput = amount of work completed per unit time.
Latency = time taken to respond to a single request.
Q47. Worst Case Execution Time (WCET)?
Maximum execution time a task can take under worst-case conditions.
Q48. Response Time?
Time from event occurrence to task completion.
13. Practical Questions
Q49. How do you debug task starvation?
Possible causes:
- Incorrect priorities
- Infinite loops
- Missing delays/yields
- High CPU usage
- Long critical sections
Q50. Why is a high-priority task not running?
Check:
- Blocked on a resource?
- Waiting for an event?
- Waiting on a semaphore?
- Interrupt disabled?
- Scheduler locked?
Q51. CPU usage is 100%. What will you check?
- Infinite loops
- Busy waiting
- High-frequency interrupts
-
Missing
sleep()/delay() - Task priorities
Q52. How do you measure context-switch time?
- Toggle a GPIO around the switch
- Use a logic analyzer or oscilloscope
- Use CPU cycle counters (e.g., ARM DWT CYCCNT)
- Use RTOS trace tools (Percepio Tracealyzer, SEGGER SystemView)
14. Coding Questions
- Implement a producer-consumer problem using semaphores.
- Write a circular queue.
- Design a software timer.
- Implement a task scheduler (basic).
- Synchronize two tasks using a binary semaphore.
- Detect deadlock in a simple system.
- Demonstrate priority inversion and explain how to fix it.
Common RTOS Interview Scenario Questions
- A high-priority task is missing its deadline. How would you investigate?
- How would you choose task priorities in an automotive ECU?
- When would you use a mutex instead of a semaphore?
- How do you safely share a CAN driver between multiple tasks?
- How would you design a periodic task that runs every 10 ms with minimal jitter?
- What happens if an ISR takes too long to execute?
- How can priority inversion occur in a CAN communication stack, and how would you prevent it?
- Why are dynamic memory allocation and unbounded blocking often avoided in safety-critical systems?
These questions cover the concepts most commonly assessed in embedded systems, AUTOSAR Classic, and automotive ECU interviews. Understanding not just the definitions but also the reasoning, trade-offs, and practical examples behind each topic will help you perform well in technical discussions.
Post a Comment