Interview Q & A 7

Interview Q & A 7

Ques 1. what is the priority inversion?
	If a low priority task holds the shared resource using semaphore that is required by the high priority task.
The high priority task has to wait till it completes the task. This is done by increasing the low priority 
task to high till it completes the task and once the finishes the task then it releases the resource to
high priority task. This is called priority inversion.

Ques 2. what are different memory segments of a program?

The memory segments are 

Stack segment:
	Here the local variables , arguments passed to the function, function return address, 
interrupt return address will be stored in stack. Stack grows from high memory to low memory.

Heap segment : This segment is used to allocate memory dynamically. It grows from low memory ot high.
we can allocate memory to pointers here.	
Uninitialised data segment:
Uninitialised data will be stored here.

Initialised data segment:
Initialised data will be stored here

Code segment:
The code and the constants will be stored here.

Ques 3. what is the difference between polling and interrupt?
	Polling : the system checks the IO devices is they need any cpu service and then do its service, this is called polling
        Interrupt: the IO device request the cpu to execute its service. this is called interrupt.

Some difference between interrupt and polling as follows:
	Device notify cpu that it needs cpu attention.
	Interrupt is a hardware mechanism
	An interrupt request line indicates the device needs a cpu service
        Interrupt handler services the device.
	The cpu is disturbed only when the device needs service, here the cpu cycles are saved.
        An inetrrupt can occur at any time
        Inerrupt is in efficient if the devices interrupting the cpu frequently

	CPU checks in regular interval if any device is ready for service. 
	Polling is software mechanism.
	Command ready bit indicates the device is ready for service.
	CPU service the device
	Cpu has to check whether a device needs service regularly this wastes lots of cpu cycles.
        CPU Polls the devices at regular intervals. 
	polling becomes inefficient if the cpu finds the device rarly ready for the service.

Ques 4. what is semaphore?
 Semaphore is proposed by Dijkstra in 1965 is very significant technique, for solving the synchronisation issue in parallel processing.
Semaphore is simply nonnegative variable holding a number and shared between threads. 
This variable is used to solve critical section problem and to achieve process sychronisation mechanism.

There are two types of semaphores
  Binary semaphore: it is also called as mutex lock. when the thread want to use a resource then it take the
  semaphore uses the resource then it release the semaphore.

  Counting semaphore: it is used when the resources are more than one. If the thread wants to use the 
  resource then it take the semaphore and decrease the semaphore count, if another thread wants the resource then 
  it take the semaphore and decrement the count. After using the resource they release the semaphore and increment the count. 

Ques 5. what is mutex?

	Mutual exclusion object shortly called as Mutex.  Mutex is a locking mechanism. The thread uses the mutex, 
lock the mutex uses the resources then the same thread unlock the mutex. Only one process can use the mutex at a time.
Mutex allows the all threads to use mutex but one at a time.
The program requests the system to create a mutex object for a resource with an ID. when the thread wants to use the resource 
it will lock the mutex uses the resource then it unlocks the resource.

Ques 6. What is synchronous communication?
example communication happened between two people over the telephone.
communication happened with respect to clock signal is called synchronous communication.
synchronous devices require the clock has to be same in receiver and transmitter.
The receiver can sample the signal at the same time interval as the transmitters send the data.

Ques 7. what is watchdog timer?

the watchdog timer continuously counts and some malfunction occured in the system it will reset the system.
The watchdog timer has to be serviced before the watchdog timer expires. if some malfunction occured in system, then it wouldnot service
the watchdog timer. then it will reset the system.

Ques 8. Find the size of the structure ?

struct st1{
int var1;
char ch1;
int var2;
float f1;

Ans : 16 bytes.
 In 32 bit system the memory is allocaed in 32 bit size. To make the memory accessing faster it write/reads 32 bit data at a time.
thats why it allocates 4 bytes to char.and others to 4 bytes as usual. in case of char one byte for data and other 3 bytes store garbage.
to effectively use the memory all chars to be placed at one place, other 4 byte sized datatypes at another location.
we can pack the datatypes using #pragam pack(1) defination above the main function.

Ques 9. Convert Binary to decimal for the below numbers?

1 * 2^0 = 1 *1 = 1
1 * 2^1 = 1 *2 = 2
1 * 2^2 = 1 *4 = 4
1 * 2^3 = 1 *8 = 8
0 * 2^4 = 1 *0 = 0
0 * 2^5 = 1 *0 = 0
1 * 2^6 = 1 *64 = 64
1 * 2^7= 1 *128 = 128

Ques 10. find the size for the following?

char arr[6];
int iarr[8];
int *p;

the sizeof arr is 6 bytes
the sizeof iarr is 32 bytes
the sizeof p is 4 bytes

Ques 11. write the truth table for xor gate & or gate?

the truth table for XOR gate:
A   B   O/p
1   1    0
0   0    0
1   0    1
0   1    1

the truth table for OR gate:
A   B   O/p
1   1    1
0   0    0
1   0    1
0   1    1

Ques 12. what is the output for the below code?

#include< stdio.h >
#include< stdlib.h >

int main()
    int  arr[8] ={0,1,2,3,4,5,6,7,8};
    int i;
    for(i=2; i<8 ;i++)
        arr[arr[i]] = arr[i];
    for(i=0; i<8 ; i++)
        printf("%d ", i, arr[i]);
    return 0;

ans: 0 1 2 3 4 5 6 7