0% found this document useful (0 votes)
24 views14 pages

Rtos

Uploaded by

e218221001003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views14 pages

Rtos

Uploaded by

e218221001003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

1. what is a non reentrant code?

-
Re entrant code is code which does not rely on being executed without inte
rruption before completion. Reentrant code can be used by multiple, simult
aneous tasks. Reentrant code generally
does not access global data. Variables within a reentrant function are alloc
ated on the stack, so each instance of the function has its own private data
. Nonreentrant code, to be used safely by multiple
processes, should have access controlled via some synchronization metho
d such as a semaphore.

2. how is RTOS different from other OS?


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

3. Is unix a multitasking or multiprocessing operating system? whats the diffe


rence between the two?
-
unix is a multitasking operating system, multiprocessing means it can run
on multiple processors, the multiproceesing os coordinates with multiple pr
ocessors running in parallel.

4. what is a core dump?


-
A core dump is the recorded state of the working memory of a computer pr
ogram at a specific time,
generally when the program has terminated abnormally includes the progra
m counter and stack pointer, memory management information, and other
processor and operating system flags and information a fatal error usually tri
ggers the core dump, often buffer overflows, where a programmer allocates too little
memory for incoming or computed data, or access to null pointers, a common codin
g error when an unassigned memory reference variable is accessed
5. what is stack overflow and heap overflow?
stack overflow occurs when when the program tries to access memory that
is outside the region reserved for the call stack
call stack contains the subroutines called, the local variables
-
overflow occurs when too many functions are called,huge amount of local
variables are allocated
6. windows also has multiple processes has process priotities switches betw
een multiple process, how RTOS is different from that?
RTOS has predictable timing constranints

7. how will u create a process in UNIX or our OS OSE?

-
We can use thr fork system call to create a process in UNIX and in OSE th
e system call create_process is used.
8. what is a flat memory model and a shared memory model?
-
in a flatmemory model the code and data segment occupies single address
space.
-
in a shared model the large memory is divided into different segments and
needs a qualifier to identify each segment
-
in a flat memory model the programmer doesnt need to switch for data and
code

9. what is paging, segmentation y do we need it?

Paging
-
Paging is a techinque where in the OS makes available the data required a
s quickly as possible. It stores some pages from the aux device to main me
mory and when a prog needs a page that is not on the main memory it fetch
es it from aux memory and replaces it in main memory. It uses specialised
algorithms to choose which page to replace from in main memory.

Caching
-
It deals with a concept where the data is temperorarily stored in a high spee
d memory for faster access. This data is duplicated in cache and the original
data is stored in some aux memory. This concepts brings the average acce
ss time lower.

Segmentation
-
Segmentation is a memory management scheme. This is the technique use
d for memory protection. Any accesses outside premitted area would result
in segmentation fault.

Virtual Memory
This technique enables non-
contiguous memory to be accessed as if it were contiguous. Same as
paging.

10. write a code to check whether a stack grows upwards or downwards?


void checkStack()

int i=2;

int j=3;

if(&i > &j) printf("stack grown downwards");


else printf("stack grows upwards");

define 2 local variables one after other and try to print the address

11. why do we require semaphore?

For process synchronization, it is a mechanism to invoke the sleeping proc


ess to become ready for execution. Its mechanism where a process can wai
t for resources to be available.typical example is
producer consumer process. The producer process creates resources and
signals the semaphore saying resource is available. Consumer process wai
ting on the semaphore gets the signal that resource is available.

12. write a small piece of code protecting a shared memory variable with a se
maphore?

int global_i;

void increment_shared_memory
{
wait(semaphore);
global_i++;
signal(semaphore);
}

13. what are the different types of semaphores and where they are used?

Binary semaphore and counting semaphore. Binary semaphore is same as


mutex. Binary semaphore tries to protect only one resource.

Counting semaphore is used in case of multiple resource. For ex: we have


4 printers then the counting semaphore value will be init to 4. When it reach
es 0, the task waiting on the semaphore is suspended.

14. what are the different inter process communications?

semaphore, mutex, message passing, shared memory, socket connections

15. what is present in .bss


The bss section contains uninitialized data, and is allocated at run-
time. Until it is written to, it remains zeroed

16. what are the different segments of a program (code, data,stack,heap etc)

memory Segments: Code segment


-
This phrase used to refer to a portion of memory or of an object file that co
ntains executable
computer instructions. It is generally readonly segment.

data segment
-
This is one of the sections of a program in an object file or in memory, whi
ch contains the global variables that are initialized by the programmer. It ha
s a fixed size, since all of the data in this section is set by the programmer
before the program is loaded. However, it is not read-
only, since the values of the variables can be altered at runtime.

.bss
This segment of memory is part of data segment that contains uninitialized
data (static variables). These are initialized to 0 and later assigned values d
uring runtime.

stack segment
-
This segment of memory is a special stack which stores information about
the active subroutines of
a task. It contains the return address to be branched to after a sub-
routine has finished execution. It contains local variables of the sub-
routines and the parameters that are passed to those sub routines.

heap segment
-
The segment of memory which is used for dynamic memory allocation is k
nown as heap. It is the responsibility of the programmer to deallocate it afte
r its use. Or alternatively it will be garbage collected by the OS.
17. what is OS scheduling mechanism in our OSE?
18. how and wher the context related information is stored PCB i guess
19. what is a make command and what are al its uses?
20. what if no process responding how it is handled (watch dog timeout me
chanism)

21. what is an ELF


-
Executable and Linking Format is a common standard file format for execu
tables, object code, shared libraries, and core dumps.

22. what is priority inversion?


-
In a scenario where a low priority task holds a shared resource (example s
emaphore) that is required by a high priority task. This causes the executio
n of the high priority task to be blocked
until the low priority task has released the resource. This scenario is averte
d by the OS by increasing the priority of the low-
proi process until it completes the task and releases the resources.
23. Locality of reference:It deals with a process accessing a resource multip
le times. There are three type of localities namely
temporal -
A resource is referenced at point in time and will be referenced again in ne
ar future. spatial -
The concept that the likelihood of referencing a resource is higher if a res
ource near it has been referenced.
sequencial The concept of accessing the memory sequentially.

SHORT NOTES ON INTERRUPT HANDING

1) An interrupt is generated by some HW source or SW source (timer or


software event).
2) CPU invokes the kernal interrupt handler.
3) Kernal interrupt handler invokes the vector handler which returns the
vector number. (Vector handler has the mapping from vector number to
interrupt source).
4) Kernal invokes the mask handler which masks all existing equal or low
priority interrupts.
5) In interrupt routine associated with the vector number is invoked.
6) Kernal invokes the mask handler again to restore old mask.

THREAD POOLING

Thread pool is a collection of managed threads usually organized in a


queue, which execute the tasks in the task queue.

Creating a new thread object every time you need something to be


executed asynchronously is expensive. In a thread pool you would just
add the tasks you wish to be executed asynchronously to the task queue
and the thread pool takes care of assigning an available thread, if any, for
the corresponding task. As soon as the task is completed, the the now
available thread requests another task (assuming there is any left).

DIFFERENT TYPES OF MEMORY FRAGMENTATION

In computer storage, fragmentation is a phenomenon in which storage spac


e is used inefficiently, reducing storage capacity and in most cases perfor
mance. The term is also used to

RTOS VS GENERAL PURPOSE OS

The biggest difference is determinacy. An RTOS will have a deterministic s


cheduler. For any
given set of tasks your process will always execute every number of micro
seconds or milliseconds exactly, and the same number from schedule to s
chedule. operating system services consume only known and expected am
ounts of time
In UNIX or Windows the scheduler are usually softreal-
time (as opposed to some hardreal time RTOS). Softreal-
time means that the scheduler tries to assure your process runs every X nu
mber of milliseconds, but may fail to do so on some occasions.

Modern RTOSs simply make sure that a) no interrupt is ever lost, and b) no
interrupt can be blocked by a lower priority process.

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 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.

You might also like