Rtos interview questions, Your interviewer might Ask

Rtos interview Questions

There are a lot of companies that are using RTOS for their products and many RTOS available in the market. So it is the reason nowadays a lot of opportunities available for the RTOS developer. If you are looking for RTOS Interview Questions & Answers for Experienced or Freshers, then you are at the right place. I will update this Rtos interview questions article regularly.

You can also like the below-mentioned articles and courses,

In this article, I have tried to collect Rtos Interview questions that can ask by your Interviewer. I hope these Rtos Interview questions help you to get a new job. I will also try to convert this Rtos Interview questions article pdf format.

 

What do you mean by a real-time system?

A real-time system is a time-bound system that has well-defined fixed time constraints. Processing must be done within the defined constraints or the system will fail.

 

What is RTOS?

RTOS stands for Real-Time Operating System. It specially designed to run the application with very precise timing and a high degree of reliability. An RTOS system must have response time predictability and it must be deterministic.

 

How is RTOS different from other OS?

RTOS offers services that allow tasks to be performed within predictable timing constraints.

 

What are the different interprocess communications?

Semaphore, mutex, message passing, shared a memory, socket connections.

 

What is the kernel?

The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. On most systems, it is one of the first programs loaded on start-up (after the bootloader). It handles the rest of the start-up as well as input/output requests from software, translating them into data-processing instructions for the central processing unit. It handles memory and peripherals like keyboards, monitors, printers, and speakers.

 

What is multitasking in the OS?

Multitasking allows the user to run several tasks at the same time. However, only one task is active at a time for user interaction, but the processing ability of the computer’s processors is so fast and smooth that it gives the impression of performing multiple tasks at the same time.

 

What is the stack overflow?

If your program tries to access beyond the limit of the available stack memory then stack overflow occurs. In other words, you can say that a stack overflow occurs if the call stack pointer exceeds the stack boundary.

If stack overflow occurs, the program can crash or you can say that segmentation fault that is the result of the stack overflow.

 

What is the cause of the stack overflow?

In the embedded application we have a little amount of stack memory as compare to the desktop application. So we have to work on embedded applications very carefully either we can face the stack overflow issues that can be a cause of the application crash.

Here, I have mentioned some causes of unwanted use of the stack.

1. Improper use of the recursive function.
2. Passing to many arguments in the function.
3. Passing a structure directly into a function.
4. Nested function calls.
5. Creating a huge size local array.

 

What is the core dump?

In computing, a core dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has crashed or otherwise terminated abnormally.

On many operating systems, a fatal exception in a program automatically triggers a core dump. By extension, the phrase “to dump core” has come to mean in many cases, any fatal error, regardless of whether a record of the program memory exists. The term “core dump”, “memory dump”, or just “dump” has also become jargon to indicate any storing of a large amount of raw data for further examination or other purposes.

 

What is the volatile keyword?

The volatile keyword is a type qualifier that prevents the objects from the compiler optimization. According to the C standard, an object that has a volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. You can also say that the value of the volatile-qualified object can be changed at any time without any action being taken by the code. If an object is qualified by the volatile qualifier, the compiler reloads the value from memory each time it is accessed by the program that means it prevents from cache a variable into a register. Reading the value from memory is the only way to check the unpredictable change of the value.

 

What is the use of volatile keyword?

The volatile keyword is mainly used where we directly deal with GPIO, interrupt or flag Register. It is also used where a global variable or buffer is shared between the threads.

 

The Proper place to use the volatile keyword?

Here I am pointing some important places where we need to use the volatile keyword.

1. Accessing the memory-mapped peripherals register or hardware status register.

#define COM_STATUS_BIT  0x00000006

uint32_t const volatile * const pStatusReg = (uint32_t*)0x00020000;


unit32_t GetRecvData()
{
    //Code to recv data
    while (((*pStatusReg)  & COM_STATUS_BIT) == 0)
    {
        // Wait until flag does not set
    }

    return RecvData;
}

 

2. Sharing the global variables or buffers between the multiple threads.

3. Accessing the global variables in an interrupt routine or signal handler.

volatile int giFlag = 0;

ISR(void)
{
    giFlag = 1;
}

int main(void)
{
    while (!giFlag)
    {
        //do some work
    }
    return 0;
}

 

What is ISR?

An ISR refers to the Interrupt Service Routines. These are procedures stored at specific memory addresses which are called when a certain type of interrupt occurs. The Cortex-M processors family has the NVIC that manages the execution of the interrupt.

 

What is the endianness?

The endianness is the order of bytes to store data in memory and it also describes the order of byte transmission over a digital link. In the memory data store in which order depends on the endianness of the system, if the system is big-endian then the MSB byte store first (means at lower address) and if the system is little-endian then LSB byte store first (means at lower address).

Some examples of the little-endian and big-endian system.

 

What is big-endian and little-endian?

Suppose, 32 bits Data is 0x11223344.

little-endian

Big-endian

The most significant byte of data stored at the lowest memory address.

 

Little-endian

The least significant byte of data stored at the lowest memory address.

Note: Some processors can switch one endianness to other endianness using the software means it can perform like both big-endian or little-endian at a time. This processor is known as the Bi-endian, here are some architecture (ARM version 3 and above, Alpha, SPARC) who provide the switchable endianness feature.

 

Write a c program to check the endianness of the system?

 

#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    uint32_t data;
    uint8_t *cptr;
    
    data = 1; //Assign data
    cptr = (uint8_t *)&data; //Type cast
    
    if (*cptr == 1)
    {
        printf("little-endiann");
    }
    else if (*cptr == 0)
    {
        printf("big-endiann");
    }
    
    return 0;
}

Output:

check endianees

 

Code Explanation:

If your machine is little-endian, the data in the memory will be something like the below expression:

    higher memory
       ----->
 +----+----+----+----+
 |0x01|0x00|0x00|0x00|
 +----+----+----+----+
 ^
 |
&data

(uint8_t *)&data = 1;

But if your machine is big-endian, it will look like the below expression:

+----+----+----+----+
 |0x00|0x00|0x00|0x01|
 +----+----+----+----+
 ^
 |
&data

(uint8_t *)&data = 0;

 

How to Convert little-endian to big-endian vice versa in C?

 

#include <stdio.h>
#include <inttypes.h>

//Function to change one endian to another
uint32_t ChangeEndianness(uint32_t u32Value)
{
    uint32_t u32Result = 0;
    u32Result |= (u32Value & 0x000000FF) << 24;
    u32Result |= (u32Value & 0x0000FF00) << 8;
    u32Result |= (u32Value & 0x00FF0000) >> 8;
    u32Result |= (u32Value & 0xFF000000) >> 24;
    return u32Result;
}

int main()
{
    uint32_t u32CheckData  = 0x11223344;
    uint32_t u32ResultData =0;

    //swap the data
    u32ResultData = ChangeEndianness(u32CheckData);

    //converted data
    printf("0x%x\n",u32ResultData);

    return 0;
}

Output:

0x44332211

Little endian to Big endian

 

 

What is virtual memory?

Virtual memory is part of memory management techniques and it creates an illusion that the system has a sufficient amount of memory. In other words, you can say that virtual memory is a layer of indirection.

 

What is Thread?

A thread is a basic unit to which the operating system allocates processor time. A thread can execute any part of the process code, including parts currently being executed by another thread.

 

What are the processes?

An application consists of one or more processes. A process, in the simplest terms, is an executing program. One or more threads run in the context of the process.

 

What are the differences between process and thread?

Threads differ from traditional multitasking operating-system processes in several ways:

  • The processes are typically independent, while threads exist as subsets of a process.
  • The processes carry considerably more state information than threads, whereas multiple threads within a process share process state as well as memory and other resources.
  • The processes have separate address spaces, whereas threads share their address space.
  • The processes interact only through system-provided inter-process communication mechanisms.
  • Context switching between threads in the same process typically occurs faster than context switching between processes.

 

 

What is a reentrant function?

In computing, a computer program or subroutine is called reentrant if it can be interrupted in the middle of its execution and then safely be called again (“re-entered”) before its previous invocations complete execution. The interruption could be caused by an internal action such as a jump or call, or by an external action such as an interrupt or signal. Once the reentered invocation completes, the previous invocations will resume correct execution.

 

What is semaphore?

Semaphore is simply a variable that is non-negative and shared between threads. This variable is used to solve the critical section problem and to achieve process synchronization in the multiprocessing environment. A semaphore is a signaling mechanism, and a thread that is waiting on a semaphore can be signaled by another thread.

 

What is mutex?

A Mutex is a mutually exclusive object which protects the shared resources from simultaneous access by multiple threads or processes. It acts as a gatekeeper to a section of code allowing one thread in and blocking access to all others. This ensures that the code being controlled will only be hit by a single thread at a time.

Mutex work on the locking mechanism, the thread which locks the mutex can only unlock it. So you must release the mutex after its use either it causes serious issues.

 

What will happen if a non-recursive mutex is locked more than once?

If a thread that had already locked a mutex, tries to lock the mutex again, it will enter into the waiting list of that mutex, which results in a deadlock. It is because no other thread can unlock the mutex.

 

Are binary semaphore and mutex same?

No both are different.

 

How to preserve stack space?

Here, I am mentioning a few points which save the stack. If you want to update this list then you can comment in the comment box.

  • Don’t pass the structure variable in a function. Use the pointer or reference to passing it in a function.
  • Instead of A() calling B() which calls C() which calls D(), have A() call B(), C(), and D() itself.
  • If a function is only referenced once, mark it inline (assuming your compiler supports this).
  • Turn on your compiler optimization.
  • Increase your compiler optimization level.

 

How RTOS does the task switching from interrupts?

The ISR has to be implemented in a way that allows for a context switch. Typically, at the end of the ISR, there will be a call to an RTOS function that checks for and performs the context switch.

When the interrupt occurs, the CPU saves its context and jumps to the ISR. The way the context is saved varies among CPU families. When the ISR is complete, it should call a special RTOS routine that allows for a context switch after an ISR. If there is a higher priority task ready to run then this routine will perform a context switch. It will take the pre-interrupt context saved by the CPU and save it with TASK_1. Then it will get the saved context of TASK_2 and restore it into the CPU such that when the end-of-interrupt instruction is called, execution returns to the context of TASK_2.

Note: The details of all of this are very CPU and RTOS-dependent.

 

What is PendSV?

PendSV is an interrupt-driven request for system-level service. In an OS environment, use PendSV for context switching when no other exception is active.

 

What is SVCall?

A supervisor call (SVC) is an exception that is triggered by the SVC instruction. In an OS environment, applications can use SVC instructions to access OS kernel functions and device drivers.

 

What is SysTick?

A SysTick exception is an exception the system timer generates when it reaches zero. The software can also generate a SysTick exception. In an OS environment, the processor can use this exception as a system tick.

 

What is UsageFault (ARM)?

A UsageFault is an exception that occurs because of a fault related to instruction execution. This includes:

1. An undefined instruction
2. An illegal unaligned access
3. Invalid state on instruction execution
4. An error on exception return.

The following can cause a UsageFault when the core is configured to report them:

1. An unaligned address on word and halfword memory access
2. Division by zero.

 

Are Interrupts are left disabled during the entire initialization process?

Yes. According to the threadX RTOS, Interrupts must be disabled during the entire initialization process. If somehow interrupts enables, then unpredictable behavior may occur.

 

 

Some unsolved Rtos interview questions for you:

  • How to create a software Timer?
  • How to creates a Task in Rtos?
  • How to send an event between different modules?
  • What is context switching?
  • What is the Advantage of RTOS?
  • What is the difference between RTOS VS GPOS?
  • What is deadlock?
  • What is the core dump and how you can resolve the core dump issue?
  • What is Thrashing?
  • Differences between mutex and semaphore?
  • What are the benefits of multithreaded programming?
  • What are the process and process tables?
  • What is time slicing?
  • What are message queues and pipes?
  • How to use the watchdog timer in an RTOS?
  • Define a device driver in your words.
  • How PendSV is used for Context Switching in FreeRTOS?
  • What is the difference between Deadlock and Starvation in OS?
  • What is priority Inversion?
  • What is priority Inheritance?
  • What is preemptive priority scheduling?
  • What are top-down and bottom-up methodologies?
  • What is an example of priority-based preemptive scheduling?
  • Explain the various types of real-time systems.

2 comments

    1. Thread-safe code is a piece of code that will work correctly during simultaneous execution by multiple threads. I will write an article on thread-safe.

Leave a Reply

Your email address will not be published. Required fields are marked *