Windows Driver (KMDF) Interview Questions

  1. Draw Windows Phone 8 Architecture?
  2. What is WDF? Advantages over WDM?
  3. What is KMDF?
  4. Difference between KMDF and WDM?
  5. Types of drivers supported in KMDF?
  6. Structure of KMDF?
  7. What is the significance of function driver, filter driver and bus driver?
  9. What is method, properties? How to define Methods and properties?
  10. Which is the ROOT object for any device object?
  11. What is attribute?
  12. What is the use of EvtCleanupCallback and EvtDestroyCallback callback methods?
  13. What is Synchronization Scope? and types
  14. What is context area?
  15. What is the process involved in Object creation and object deletion?
  16. How the Drivers can change the parent of KMDF objects?
  17. What is IRP?
  18. Explain IO Request Flow?
  19. Job of I/O Request Handler?
  20. Types of IO Requests?
  21. What will happen if the driver has neither registered a call back nor configure the queue for IO requests?
  22. What is Queue and its operation?
  23. Dispatch types?
  24. Execution Level and Locks Usage?
  25. Wait locks and spin locks?
  26. Define the steps to create KMDF object?
  27. Configuration structure and attributes structure of Object?
  28. What is DPC?
  29. What is INF file?
  30. How to create Interupt Object?
  31. What is EvtinterruptIsr and EvtInterruptDpc?
  32. What is post interrupt enable and pre interrupt disable?

Interview Questions

C Objective

         unsigned int i;
              printf("c aptitude");

i is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.

          float i=1.5;
           case 1: printf("1");
           case 2: printf("2");
           default : printf("0");
Compiler Error: switch expression not integral

Switch statements can be applied only to integral types.

Data Conversion Functions in C

Converts string to float
Converts string to int
Converts string to long
Converts double to string
Converts double to string
Converts double to string
Converts int to string
Converts long to string
Converts string to double
Converts string to long integer
Converts string to an unsigned long integer
Converts unsigned long to string

Write a c program to find the size of int without using sizeof operator

 int main()  
     int *ptr = 0;  
     printf("Size of int data type: %d",ptr);  
  return 0;  

How to find the size of the Structure without using sizeof() operator in C


struct sample{
       int num;
       char addr;
       float val;
int main(){
       struct sample *ptr = 0;
       printf("Size of the structure sample: %d",ptr);
       return 0;

Size of the structure sample: 9

Compiler,Assembler,Linker and Loader

C Programs Building  process based on four stages.

  1. Preprocessing is the first pass of any C compilation. It processes include-files, conditional compilation instructions and macros.
  2. Compilation is the second pass. It takes the output of the preprocessor, and the source code, and generates assembler source code.
  3. Assembly is the third stage of compilation. It takes the assembly source code and produces an assembly listing with offsets. The assembler output is stored in an object file.
  4. Linking is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation)


1) int const* p
     const int * p
      both indicates “p” is a pointer that points to a constant integer
      Hence “(*p)++ “ , “(*p)-- “ are not possible

int * const p
    indicates that p is constant pointer and it contains the address of an integer. 
    Hence “p++”, “p --” are not possible

Storage classes in C

Keyword : auto
Storage Location : Stack
Initial Value : Garbage Value
Life : Control remains in a block where it is defined
Scope : Local to the block in which variable is declared

Keyword : register
Storage Location : CPU Register
Initial Value : Garbage
Life : Local to the block in which variable is declared.
Scope : Local to the block

Keyword : extern
Storage Location : if uninitialized then in BSS, if initialized then in Data segment
Initial Value : Zero
Life : Until the program ends.
Scope : Global to the program

Keyword : Static
Storage Location : if uninitialized then in BSS, if initialized then in Data segment
Initial Value : Zero and can be initialize once only
Life : Depends on function calls and the whole application or program
Scope : Local to the block

Incrementing and Decrementing Pointers

      int *a,*s,i;
      printf("%d\n",(*++s)++); //Increments address by 4 and then value
      printf("%d\n",(*s)++); //Increments value only
      printf("%d\n",*++s); //Increments address only
      printf("%d\n", ++*s ); //Increments value only
      printf("%d\n",++s++); //Error



 int a;                                An integer
 int *a;                              A pointer to an integer
 int **a;                            A pointer to a pointer to an integer
 int a[10];                        An array of 10 integers
 int *a[10];                      An array of 10 pointers to integers
 int (*a)[10];                    A pointer to an array of 10 integers
 int (*a)(int);                    A pointer to a function a that takes an integer argument and returns an integer
 int (*a[10])(int);            An array of 10 pointers to functions that take an integer argument and return an integer 

Write a macro for square of a number?

#define SQUARE(x) ((x) * (x))

Linux: Kernel

A kernel is a central component of an operating system. It acts as an interface between the user applications and the hardware. The sole aim of the kernel is to manage the communication between the software (user level applications) and the hardware (CPU, disk memory etc). The main tasks of the kernel are :
  • Process management 
  • Device management 
  • Memory management 
  • Interrupt handling 
  • I/O communication 
  • File system...etc..

What is a PCB (process control block)? What is its significance in the kernel?

A process control block or PCB is a data structure (a table) that holds information about a process. Every process or program that runs needs a PCB. When a user requests to run a particular program, the operating system constructs a process control block for that program. The PCB contains important information about the specific process including:-
  • The current state of the process i.e., whether it is ready, running, waiting, or whatever. 
  • Unique identification of the process in order to track "which is which" information. 
  • A pointer to parent process. 
  • Similarly, a pointer to child process (if it exists). 
  • The priority of process (a part of CPU scheduling information). 
  • Pointers to locate memory of processes. 
  • A register save area. 
  • The processor it is running on.

To find out big endian or little endian

int main()
             unsigned int i = 1;
             char *c = (char*)&i;
             if (*c)
                   printf("Little endian");
                   printf ("Big endian");
             getchar ();
          return 0;
In the above program, a character pointer c is pointing to an integer i. Since size of character is 1 byte when the character pointer is de-referenced it will contain only first byte of integer. If machine is little endian then *c will be 1 (because last byte is stored first) and if machine is big endian then *c will be 0.

Semaphore and Mutex

A Mutex controls access to a single shared resource. It provides operations to acquire() access to that resource and release() it when done.

A Semaphore controls access to a shared pool of resources. It provides operations to Wait() until one of the resources in the pool becomes available, and Signal() when it is given back to the pool.

There are two types of Semaphores:
  1. Counting Semaphore
  2. Binary Semaphore                                
When number of resources a Semaphore protects is greater than 1, it is called a Counting Semaphore. When it controls one resource, it is called a Binary Semaphore. A Binary semaphore is equivalent to a mutex.

Why there are no virtual constructors but there are virtual destructors?

To call a virtual constructor, the V-table should be already in memory. However, there is no pointer to v-table in memory because the object has not been created. The object will be created when you have the constructor in place.

Android: Multimedia Interview Questions

1) Explain the android architecture?
2) Explain the code flow for audio playback scenario and video playback scenario?
3) Explain the state diagram of media player object?
4) What is MM framework and explain about open core and stage fright?
5) Diff b/w Open core and Stage fright?
6) Explain Stage fright architecture?
7) What is OpenMax IL?
9) What are the call back functions in OpenMax IL?
10) What is ‘role of OMX_Component”?
11) How will you implement an OMX Component?
12) What is the use of OpenMax IL?
13) When “setparam” and “setconfig” functions will be used?
14) When “AllocateBuffer” and “Usebuffer” functions will be called?
15) What is the role of awesome player in Stage fright?
16) How will you integrate an s/w codec or hardware codec with stage fright?
17) How the player type is decided for playback of particular file format?
18) What is Meta data and how will it be extracted?
19) Will stage fright support all media file formats?
20) How the thumbnail image will be created?
21) What is role media scanner?
22) What is the role of media extractor?
23) What is the role of metadata retriever?
24) What is the functionality of Audio flinger?
25) What is the functionality of surface flinger?
26) What is the role of Audio policy Service and Audio Policy Manger?
27) Explain the State diagram of Phone state?
28) How Application Processor and Communication Processor will be communicated?
29) What are the native services that will start from media server?
30) How player app and media player service will be communicated?
31) What is Binder?
32) What are the IPC methods used in android?
33) How AV sync is managed during video playback?
34) How the buffer management will be done for playback and recording?
35) What is PMEM and ashmem?
36) What is audio track and audio sink in the context of playback?
37) What is mutex, and when it is used?
38) What is parser and renderer, will these be OMX Components?
39) How would you know whether s/w codec or h/w codec is used?
41) What is frame buffer?
42) What is egl swapbuffers?

43) What is parser? 
44) What is recogniser?
45) What is Payload?
46) Explain Power Saving Machanisam in Audio/Video Playback?
47) Explain Interrupts handling in Audio Playback?
48) Why up sampling and down sampling is required while routing different audio streams 
49) Which is the flag we set when playback complete in OMX Component?
50) What a mp4 file header have in it? 51) What does Media Scanner do?
52) Where is thumbnail stored in a picture?
53) How AV sync is achieved in RTSP streaming?
54) In RTSP streaming, what RTCP Packets comprise of ?
55) What happens in JNI if many media player instances are created?
56) Who selects the codecs for encoding for Author Engine
57) What is the control path in RTP?
58) Which transport protocol is used in RTSP?
59) Which is preferred for streaming...? RTSP or HTTP?
60) Which is more preferred H263 or H264?
61) What is container and codec?
62) Can seek n pause operations be done in while streaming through rtsp?
63) What is interlaced and progressive streaming?
64) How do you synchronize between the audio and video streamed data?
65) Why RTSP is called real time?
66) Difference between HTTP n RTSP?
67) What is RTSP protocol?

C++ Interview Questions

  1. If a class has only parameterized constructor. Is it possible to instantiate the class without passing any parameters to constructor? Will it give compilation error in doing so if yes how can you fix it?
  2. How can you keep track of instances of a class?
  3. What is the property of static data members?
  4. Describe a situation where you can't use this pointer.
  5. Explain concept of polymorphism.
  6. What is the necessary condition for implementing run time polymorphism?
  7. What is abstract base class?
  8. Explain early binding and late binding.
  9. What is this pointer? Write a code to show the use of this pointer.
  10. Explain shallow copy and deep copy.
  11. There is anything called virtual destructor when it is necessary and why the destructor is made virtual.
  12. There are two classes; one is Base class containing one static member and another class deriving the Base. Is it possible to access the static member variable from the derived class?
  13. How can you access private static member of a class.
  14. What all things an empty class can have? What is the size of an empty class?
  15. Implement a class which can't be instantiated. 
  16. Divide by 7 without using (/) operator...basically using bitwise shifting
  17. In a copy constructor, why argument is not passed by value, and why is it passed by constant reference?
  18. What is the difference between copy constructor and assignment operator overloading?
  19. What is difference between structures and classes?

Command Line Arguments

It is possible to pass values from command line to Your C programs when they are executed. This is very important when you want control your program from outside instead of hard coding these values inside the program.

Command Line arguments are handled using main() function.
main(int argc,char *argv[])

argc: number of arguments passed to the program.
argv[]: is a pointer array which points to the each argument passed to the program.

argv[0] holds the name of the program itself.

argv[1] holds the first argument.

Write a Program to generate Fibonacci Series in C

The first two Fibonacci numbers are 0 and 1 then next number is addition of previous two numbers.
0, 1, 1, 2, 3, 5, 8, 13, 21
Fibonacci number Nth can be calculated as the formular follows:

Using Recursive Method:

int fibonacci(int num)
                return 0;
                return 1;
         return fibonacci(num-1)+fibonacci(num-2);

Using Iterative Method:

int fibonacci(int num)
          int f1=0;
          int f2=1;
          int fn;
          for(int i=2;i<n;i++)

Linux: Kernel Space and User Space

Linux kernel runs under a special privileged mode as compared to user space applications. 

Kernel runs in a protected memory space and it has access to entire hardware. This memory space and this privileged state collectively known as kernel space or kernel mode.

User space programs runs in a unprivileged mode and it has limited access to resources and hardware.

User space applications can not directly access to kernel memory but kernel has access to entire memory space.

Linux: fork() system call

System call fork() is used to create the new process,which becomes the child process of the caller.After a new child process is created ,both the will execute the next instruction following the fork() system call.

If fork() returns negative value,creation of child process unsuccessful

fork() returns “0” to the newly created child process.

fork() returns positive value,process ID of the child process to parent.

Linux will make the exact copy of the parents address space and give it to the child process. So ,the parent and child processes have separate address spaces.

        printf("hello world");
— will print 8 times.

What is Spinlock?

A spinlock is a lock where the thread simply waits in a loop ("spins") repeatedly checking until the lock becomes available. Since the thread remains active but isn't performing a useful task, the use of such a lock is a kind of busy waiting.

Spinlocks are efficient if threads are only likely to be blocked for a short period of time, as they avoid overhead from operating system process re-scheduling or context switching. For this reason, spinlocks are often used inside operating system kernels. However, spinlocks become wasteful if held for longer durations, preventing other threads from running and requiring re-scheduling.

string copy program without using strcpy()

void stringcopy(char str1[],char str2[])
           int i=0; 
int main() 
          char str1[100],str2[100]; 
          printf(“Enter the string”); 
          printf(“After copy:%s”,str2);

What is Memory Leak?

Memory Leak occurs when a computer program consumes memory but is unable to release it back to the operating system.

Using Valgrind (Linux), Purify (Windows) tools leaks can be detected.

$valgrind --tool=memcheck --leak-check=yes program name

Ex: int main()
            char *x= malloc (100);
            return 0;

printf(),fprintf(),sprintf() in C

printf(): writes the output to stdout,standard output device.
             int printf(const char *format, ...);

sprintf(): writes the output to character string in memory.
            int sprintf(char *str, const char *format, ...);

fprintf(): writes the output to the given output stream.
            int fprintf (FILE *stream, const char *format, ...);

C++ Interview Questions

  1. What are the major differences between C and C++?
  2. What are the differences between new and malloc?
  3. What is the difference between delete and delete[]?
  4. What are the differences between a struct in C and in C++?
  5. What are the advantages/disadvantages of using #define?
  6. What are the advantages/disadvantages of using inline and const?
  7. What does it mean to take the address of a reference?
  8. What does it mean to declare a function or variable as static?
  9. What is the order of initialization for data?
  10. What is name mangling/name decoration?
  11. What kind of problems does name mangling cause?
  12. How do you work around them?
  13. What is a class?
  14. What are the differences between a struct and a class in C++?
  15. What is the difference between public, private, and protected access?
  16. For class CFoo { }; what default methods will the compiler generate for you>?
  17. How can you force the compiler to not generate them?
  18. What is the purpose of a constructor? Destructor?
  19. What is a constructor initializer list?
  20. When must you use a constructor initializer list?
  21. What is a:Constructor?Destructor?Default constructor?Copy constructor?Conversion constructor?
  22. What does it mean to declare a...member function as virtual?member function as static?member function as static?member variable as static?destructor as static?
  23. Can you explain the term "resource acquisition is initialization?"
  24. What is a "pure virtual" member function?
  25. What is the difference between public, private, and protected inheritance?
  26. What is virtual inheritance?
  27. What is placement new?
  28. What is exception handling?
  29. Explain what happens when an exception is thrown in C++.
  30. What happens if an exception is not caught?
  31. What happens if an exception is throws from an object's constructor?
  32. What happens if an exception is throws from an object's destructor?
  33. What are the costs and benefits of using exceptions?
  34. When would you choose to return an error code rather than throw an exception?
  35. What is a template?
  36. What is partial specialization or template specialization?
  37. How can you force instantiation of a template?
  38. What is an iterator?
  39. What is an algorithm (in terms of the STL/C++ standard library)?
  40. What is std::auto_ptr?
  41. What is wrong with this statement?
  42. std::auto_ptr ptr(new char[10]);
  43. It is possible to build a C++ compiler on top of a C compiler. How would you do this?

How to Use memset(),memcpy(),memmove() in C

      memset() function is used to set all the bytes in a block memory to particular value.Generally this is used to set a memory location to null character '\0'.

               void *memset(void *dest,int c,size_t count);        
               dest: Pointer to the block of memory.
               c: value to be set.c is type int,but it is treated as type char.It is not useful for working           with blocks of data types other than type char,except when you want to initialize to 0.
               count: Number of bytes set to the value.


      memcpy() function is used to copies bytes of data between memory blocks.
This will copy "count" characters from the string "src" into the memory pointed to by  "dest".

               void *memcpy(void *dest,void *src,size_t count);  

               dest:destination string

               src: source string
               count: Number of bytes to copy.

Unlike strncpy function, memcpy() function does not check for the terminating '\0' of dest.
memcpy() can not handle the situation where the source string overlaps destination string.


       move block of memory.

               void *memmove(void *dest,void *src,size_t count);  

               dest:destination string
               src: source string

               count: Number of bytes to copy.

memmove() can safely handle the overlap situation.

KMDF Interview Questions

  1. What is WDF framework?
  2. what is KMDF?
  3. How to write a KMDF Driver?
  4. Difference between KMDF and UMDF?
  5. How to handle Interrupts in KMDF Driver?
  6. I/O Flow in KMDF Driver?

C Interview Questions

2) How you debug memory leaks?
3) Difference between kmalloc and vmalloc?
4) Can we find the size of memory after it was allocated?
6) What is binary search tree? 
10) Write a logic for inserting a node at the x location which can be at the start or middle or end 
      if the list?
11) Write a function to test how many bits are set in a 32 bit integer?
12) Implement logic to flip stream of 8-bit binary data and reason for selecting this method?
13) Given a double linked list and asked to WAP to sort it?
15) Write a logic for inserting a node at the x location which can be at the start or middle or end 
       if the list?
17) Setting nth bit?
18) Clearing nth bit?
19) How are enum and macro different in C?
20) Advantages of enum over macro, how are enum useful during debugging on target?
21) What is function pointer? Advantages of Function pointers? Where it is used?
22) Differentiate between new and malloc?
23) Differentiate between struct and union?
24) What is significance of union?
25) Recursive function? Advantages and disvantages?
26) Define binary tree?
27) Define data structure?
28) What is stack corruption?
29) What is stack overflow exception?
30) What is advantage of being taken static over global?
31) What is data memory? What type of data memory you know
33) Which of the above is faster /efficient (iterative or Recursion)
34) What is heap and stack? What are the variables that are stored on these?
36) In int *p, if p = 1000 then what is p++ =?
37) Pointers? How will you know the addresses of array/pointer array are word aligned?
38) Static functions in C, C++ How are they different and where do they stored in each 
39)Static variables in C, C++? Uses of Static variables?
40) Where a static variable stored in the following cases does: 
                     a. if declared inside a function,
                     b. If declared inside a file.
41) Differentiate b/w global and static variables? Where static and global variables stored?
42) What happens when functionA () calls functionB ()?
43) Difference between MACRO and “const”?
44) What is call back function?
45) How to write a value at particular address?
46)If we have two strings str1, str2, then how can we find that is str2 a permutation of str1?
47) Call by value function with case of swap function. Call swap function and then print the 
       variables, what is the o/p?
48) What is a static library and shared library?
49) If unsigned a and b are present. And if[(a-b)<0] then print good else print bad. What is o/p 
      and how to solve it?
50) What are the sections of an ELF, what is difference between BSS and DS?
51) What is Encapsulation and how to achieve in C?
52) Elaborate on Polymorphism and how to achieve in C?
53) What are Virtual Functions and How to obtain virtual functions behavior in C?
54) Call by value and reference; what is major usage difference in C, C++? 
55) How is base address of array different from const pointer?
56) How to use C function in C++? How to interface C function in C++?
57) Differentiate between new and malloc?
58) Differentiate between struct and union?
59) Order of double linked list.
60) Suppose there is a single linked list. How do you go to the nth element from the last node 
       by traversing the list only once from start?
61) What do you mean by const keyword?
62) What is size of character, integer, integer pointer, character pointer?
63) What is NULL pointer and what is its use?
65) Can structures be passed to the functions by value?
66) Why cannot arrays be passed by values to functions?
67) Advantages and disadvantages of using macro and inline functions?
68) What happens when recursion functions are declared inline?
69) #define cat(x,y) x##y concatenates x to y. But cat (cat (1, 2), 3) does not expand but gives 
      preprocessor warning. Why?
70) ++*ip increments what? It increments what ip points to?
71) Which way of writing infinite loops is more efficient than others?
72) What is a forward reference w.r.t. pointer in c?
73) How can you define a structure with bit field members?
74) How do you write a function which takes 2 arguments - a byte and a field in the byte and 
       returns the value of the field in that byte?
75) Which parameters decide the size of data type for a processor?
76) What is job of preprocessor, compiler, assembler and linker?
78) Explain about stack segment? How it grows? What are the ways to allocate memory other 
       than allocating in heap? 
79) Why stack uses LIFO’s and Queue uses FIFO’S? What is stored in stack? Differentiate 
       between stack and heap?
80) What is linked list? What is the difference between array and linked list? How to add and 
        remove the nodes in a linked list?
81)What are storage classes in C? What is Static storage class in C? How it is used (an 
82)Differentiate between C and C++?
83)How do you relate Data Encapsulation in C++ with the static storage class in C?
84)Differentiate between Arrays and Linked Lists? When you will decide to use arrays and 
        linked lists?
85)Preprocessor commands used for debugging?
86)Hash tables explanation in c?
87)What is size of Struct {
                                            int m1;
                                            short int m2;
                                            int m3;
                                            char m4;
88)What is int * const ptr?
89)What are the compile time and link time errors and how to solve those? 
90)What are the functions or properties of Make File?
91) What is data memory? What type of data memory you know
92) Implement a logic to flip stream of 8-bit binary data and reason for selecting this method
93) What is little endian and big endian?
94) Static variable is declared in 1.c file and need to edit the same static variable in 2.c file, 
          how to do this?
97) Difference between static and extern?
98) how to use static function defined in one file in another file

Linux Interview Questions

  1. How do you find files on UNIX or Linux system?
  2. What separates Unix Linux?
  3. What is a Zombie process?
  4. What is a shell?
  5. How would you know the process is a zombie?
  6. What is the best way to check the status of any service?
  7. Which daemon is used for scheduling of the commands?
  8. What is boot block?
  9. Differentiate between Process and Thread in Linux.
  10. Explain Linux Boot process especially kernel and initrd.
  11. What is the meaning of Linux Shell and Shell Script?
  12. Which field is used to define the user’s default shell?
  13. What command can you use to review boot messages?
  14. Explain one major difference between a regular file system and a journaling file system?
  15. What is the minimum number of partitions you need to install Linux?
  16. Explain the Address Space of Thread and Process.
  17. What are the IPC mechanisms which are available on Linux?
  18. How can u schedule a job using cron for 20 secs?
  19. Describe RPM and command to install / remove / update Linux system?
  20. What is fork ()?
  21. How can we see the boot messages?
  22. Which command is used to check the number of files and disk space used and the each user’s defined quota?
  23. In a UNIX environment how do you know what process is currently executing?
  24. How will you know the state of those processes?
  25. How do you differentiate Dynamic and static linking of Libs in make file
  26. How to identify little Endian or big endianness
  27. Write a script to convert all DOS style backslashes to UNIX style slashes in a list of files.
  28. How do you create a swapfile?
  29. What debuggers used?
  30. What Linux HotKeys do you know?
  31. How to switch to a previously used directory?
  32. How can you copy lines into the buffer in command mode?
  33. How you will uncompress the file?

OS & RTOS Interview Questions

1. What is priority inversion? 2. Preemptive scheduler types.
3. How to write Interrupt service routine? Can semaphore be released in ISR?
4. What is semaphore? What are its types?
5. Difference between semaphore and mutex.
6. Difference between monolithic kernel and micro kernel with exapmle.
7. If there is one process and 4 threads. How many stacks, heaps, and datasegments do u require? And why?
8. What are the important members of TCB structure?
9. Explain about task control block and process control block?
10. Explain about the critical section. Have you come across in any of your project, if so explain with a small program.
11. What is Interrupt Latency 
12. Difference btwn Wince5.0 and 6.0 Memory model.
13. How memory is allocated? (virtual memory, paging etc). What is maximum size of virtual memory can be allocated for a system?
14. Message QUE and Shared Memory. Which is Fast
15. What is Message passing?
16. How to avoid resource contention in RTOS using semaphore and Mutex, without raising task priority
17. Which is more efficient in RTOS mutex, semaphore?
18. When you will decide to create a process in an application?
19. Differentiate between process and thread?
20. Whatis RTOS? Differentiate between OS and RTOS? 
21. What is preemptive and non preemptive scheduling?
22. How do you implement mutex? POSIX APIs
23. How to do avoid thread switching while locking mutex in your C code implementation?
24. What is the difference between spinlock and mutex?
25. What is spinlock?
26. Which RTOS is your favorite?
27. What is the difference between physical address and virtual address?
28.What type of scheduling algorithms that we use in RTOS?

C - Tips

1) ++*ptr: incrments what ptr points to
     (*ptr)++ : The parentheses are necessary in this last example; without them, the expression would increment ip instead of what it points to, because unary operators like * and ++ associate right to left.

2)   int *ip,*iq;
       iq = ip;
      copies the contents of ip into iq, thus making iq point to whatever ip pointed to.

3) A[i] = *(a+i);
    int *pa,a[10];
   There is one difference between an array name and a pointer that must be kept in mind. A pointer is a variable, so pa=a and pa++ are legal. But an array name is not a variable; constructions like a=pa and a++ are illegal.

4)  char amessage[] = "now is the time"; /* an array */
      char *pmessage = "now is the time"; /* a pointer */
5) Big endian: Most significant byte at lowest address
      Little endian: Least significant byte at lowest address.
         BE: 12 34 56 78
         LE: 78 56 34 12
6) Using call by reference: we can make a function to return more than one value from function.
7) Arithmetic operation cannot be performed on void pointer.
8) int *s;
    *++s = increments the address
    ++*s = increments the value
    (*++s)++ = increments the address and then value
    (*s)++ = increments the value

Linked List Interview Questions

   1)  How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a 
         C program to do the same.
   2)  Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
   3)  How do you sort a linked list? Write a C program to sort a linked list.
   4)  How to declare a structure of a linked list?
   5)  Write a C program to implement a Generic Linked List.
   6)  How do you reverse a linked list without using any C pointers?
  7)   How would you detect a loop in a linked list? Write a C program to detect a loop in a 
         linked list.
  8)  How do you find the middle of a linked list? Write a C program to return the middle of a 
        linked list.
  9)  If you are using C language to implement the heterogeneous linked list, what pointer type 
       will you use?
 10) How to compare two linked lists? Write a C program to compare two linked lists.
 11) How to create a copy of a linked list? Write a C program to create a copy of a linked list.
 12) Write a C program to free the nodes of a linked list.
 13) Can we do a Binary search on a linked list?
 14) Write a C program to return the nth node from the end of a linked list.
 15) How would you find out if one of the pointers in a linked list is corrupted or not?
 16) Write a C program to insert nodes into a linked list in a sorted fashion.
 17) Write a C program to remove duplicates from a sorted linked list.
 18) How to read a singly linked list backwards?
 19) How can I search for data in a linked list?

What is Segmentation fault?

A segmentation fault occurs mainly when our code tries to access some memory location which it is not supposed to access.

·         Working on Dangling pointer
·         Freeing the memory twice
·         Running out of memory(stack or  heap)
·         Improper format control string in printf or scanf statements
·         Failure to initialize a pointer before accessing it

Scheduling Algorithms in RTOS

  Based on scheduling algorithms, scheduler decides the task execution. 
There are two types

·         Preemptive priority based scheduling:
o   Most real time kernels use this scheduling by default.
o   Real-time kernels generally support 256 priority levels, in which 0 is the highest and 255 thelowest. Some kernels appoint the priorities in reverse order,
o   Tasks are assigned Priority levels when they are created, task priority can be changed dynamically using kernel provided calls.
o     With a preemptive priority-based scheduler, each task has a priority, and the highest-priority task runs first.
o   Task 1 ispreempted by higher-priority task 2, which is then preempted by task 3. When task 3 completes,task 2 resumes; likewise, when task 2 completes, task 1 resumes.
·         Round Robin scheduling:
o   Round-robin scheduling provides each task an equal share of the CPU execution time.
o   Which uses time slicing toachieve equal allocation of the CPU for tasks of the same priority.
o     A run-time counter tracks the time slice for each task, incrementing onevery clock tick. When one task’s time slice completes, the counter is cleared, and the task isplaced at the end of the cycle.

If a task in a round-robin cycle is preempted by a higher-priority task, its run-time count is savedand then restored when the interrupted task is again eligible for execution. This idea is illustratedin Figure, in which task 1 is preempted by a higher-priority task 4 but resumes where it left offwhen task 4 completes.