Monday, January 30, 2012

T20 International Aus Vs Ind


1st T20I: Australia v India at Sydney
Feb 1, 2012 (19:35 local | 08:35 GMT | 14:05 IST)


2nd T20I: Australia v India at Melbourne
Feb 3, 2012 (19:35 local | 08:35 GMT | 14:05 IST)

Friday, January 27, 2012

Deadlock


Deadlock is a situation in which the processes waits for the other resource which is occupied by another process in a loop for example take processes P1 and P2 and resources R1 and R2 in the deadlock condition

        P1 -R1 waits for R2
        P2 -R2 waits for R1 

so both processes waits for the other resource to get free for their complete operation.
In such cases - One can avoid deadlocks by following methods

1) Prevention
2) Detection
3) Avoidance
4) Recovery

Digial Modulation Technique


There are three predominant methods of encoding a transmission signal. Amplitude modulation (AM), and frequency modulation (FM) are both analog modulation schemes. The third method is digital modulation.
In Digital modulation followings are involved. They are,

  • QPSK( Quadrature Phase Shift Keying )DVB-S
  • QAM( Qudrature Amplitude Modulation )CABLE
  • COFDM( Coded Orthogonal Frequency Division Mulitiplexing )DVB-T

Standards Otherthan DVB


1. ATSC
The Advanced Television Systems Committee (ATSC) is the group that helped to develop the new digital television standard for the United States, also adopted by Canada, Mexico, and South Korea and being considered by other countries.It is intended to replace the NTSC system and produce wide screen 16:9 images up to 1920×1080 pixels in size. More than six times the display resolution of the earlier standard.
2. ISDB
Integrated Services Digital Broadcasting (ISDB) is the digital television (DTV) and digital audio broadcasting (DAB) format that Japan has created to allow radio and television stations there to convert to digital.
3. ARIB
The Association of Radio Industries and Businesses, commonly known as ARIB, is a standardization organization in Japan. ARIB is designated as the center of promotion of the efficient use of the radio spectrum and designated frequency change support agency.
4. SBTVD
Brazilian Digital Television System is a proposed digital television standard for Brazil.

What is interrupt latency?


It is the time interval between an interrupt has occurred till the time it has been serviced.

Wednesday, January 18, 2012

Java Script - Redirecting to a web page



Java Script code to redirect a web page,

<script language="JavaScript">
function move_now()
{
   window.location = 'http://www.vijaynetwork.com'
}
</script>

If you call the move_now() function from a html page,it will be redirect to the vijaynetwork.com.

Saturday, January 14, 2012

Reverse a single linked list

Node *Reverse (Node *p)
{
  Node *pr = NULL;
  while (p != NULL)
  {
  Node *tmp = p->next;
  p->next = pr;
  pr = p;
  p = tmp;
  }
  return pr;
}

C program to count the number of set bits in an unsigned integer

/*
Program to count no. of bits in an unsigned integer
*/
void main( void )
{
unsigned int a = 15;
int count = 0;

while( a )
{
++count;
a = a & ( a - 1 );
}

clrscr();
printf( "Count is %d\n", count );
getch();
}

Why is sizeof('a') not 1?

Character constants in C are of type int, so sizeof('a') is sizeof(int) (though it's different in C++).
Result:
In Turbo C output is: 2
In Turbo C++ output is: 1

why n++ executes faster than n+1?

The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.

Finding middle of the single linked list in a single traversal.

Step 1:
Take two pointers P1 and P2, both pointed to the first element.
Step 2:
Increment P1 by 1 and P2 by two.
Step 3:
Whenever P2 reaches to the end, P1 will be at the middle of the list, just return P1->data.

Finding Loop in a single linked list.


Method-1
If the linked list is read only, take two pointer approach( p1, p2). Both pointing to beginning of linked list. Now increment p1 by 1 and p2 by 2 and compare both. if they are equal there is a cycle. Repeat this untill p2 points to null.

Method-2
If you have the condition not to modify the node but you can change the links, then reverse the linked list. If you reach the head node then there is a cycle.

Difference between memcpy and memmove

memmove offers guaranteed behavior if the source and destination arguments overlap. memcpy makes no such guarantee, and may therefore be more efficiently implementable. When in doubt, it's safer to use memmove.




Nibble Swap & Alternate Bit Swapping

int main( void )
{
    unsigned char  a = 40, b=20;

    a = ( a>>4 ) | ( a<<4 );

    b = ( ( b & 0xAA ) >> 1 ) | ( ( b & 0x55 ) << 1 );
   
    printf( "After Nibble Swap %d\n", a );
    printf( "Alternate Bit swapping %d\n", b );
    getch();

    return 0;
}

Few More String functions..

String Length
int strlen( char *s )
{
    char *ptr = s;

    while( *ptr++ );
    return( ptr-s );
}

String Copy
char *strcpy( char *s, char *t )
{
    char *ptr=s;
    while( *s++ = *t++ );
    return( ptr );
}

String Cat
char *strcat( char *s, char *t )
{
    char *ptr=s;

    while( *s++ );
    while( *s++ = *t++ );
    return( ptr );
}

String Compare
int strcmp( char *s, char *t )
{
    int n;
    while ((n = *s - *t++) == 0 && *s++);
    return( n );
}

String Reverse

int main( void )
{
    char     S[] = "iVijay C Programming";
    int      i, j;

    for( i=0, j=strlen(S)-1; i<((strlen(S))/2); ++i, --j )
    {
         S[i]  ^= S[j] ^=  S[i]  ^= S[j];
    }
    printf( "Reverse Is : %s\n", S );

    return 0;
}

Reverse Bits ( 16 bit )

int main( void )
{
    int a= 0xFF00, i, rev=0;

    for( i = 0; i < 16; ++i )
    {
        if( a & ( 1 << i ) )
        {
            rev |= ( 0x8000 >> i );
        }
    }
    printf( "Input is 0x%04x\n", a );
    printf( "Reverse Bit Is 0x%04x\n", rev );

    return 0;
}

Healthy Eating..

Honey & Cinnamon
It is found that mixture of Honey and Cinnamon cures most of the diseases. Honey is produced in most of the countries of the world. Ayurvedic as well as Yunani medicine have been using honey as a vital medicine for centuries. Scientists of today also accept honey as a Ram Ban (very effective) medicine for all kinds of diseases. Honey can be used without any side effects for any kind of diseases. Today's science says that even though honey is sweet, if taken in the right dosage as a medicine, it does not harm diabetic patients also.

Fish
Eat plenty of fish - fish oil helps prevent headaches. So does ginger, which reduces inflammation and pain.

Apple
Although an apple has a low Vitamin C content, it has antioxidants & flavonoids which enhances the activity of Vitamin C thereby helping to lower the risks of colon cancer, heart attack & stroke.

Strawberry-Protective Fruit
Strawberries have the highest total antioxidant power among major fruits & protect the body from cancer causing, blood vessels clogging free radicals.

Causes of cancer

Smoking is very often the main cause of cancer. It kills us silently and drains money from us quietly. There're 4,000 harmful chemicals (though in diluted form) in one stick of cigarette. Taking one puff is 600 times worst than inhaling the exhaust fumes from vehicles.
Some food that cause cancer are,
1. Barbecued Food
2. Deep Fried Food
3. Overheating Meat
4. Food that is high in fat causes our bile to secrete acid that contains a chemical which is a promoter of cancer cells.
5. Food that contains preservatives, too much salt or nitrates (e.g. Canned food, Salted egg & veggies, sausages, etc.)
6. Overnight Rice (where Aflatoxin is accumulated)
7. Food that is low in fibre: Our body needs 25 gm of both soluble & insoluble fibre daily. We must drink at least 1.5 litres of plain water a day.
8. Contaminated Food.

Tips for Winter


  • Drink lots of water to increase the amount of moisture in the body, this helps to prevent congestion. It also helps to thin the mucus for proper drainage.

  • Wear warm clothes to cover yourself.

  • Hot food like non-veg is said to keep the body warm and fit.

  • Person suffering from arthritis or osteoporosis should do regular exercise to warm up the body and stay well.

  • Taking long baths during winter can dry skin. Apply moisturizer after bath.

  • Give yourself a foot spa. Buy a warming foot scrub and use this to clean the bottom of your feet to make them soft and smooth.

  • Elbows and knees might suffer the driest patches in your body due to exposure to mist and cold. To exfoliate these dark spots, rub a lemon on the area and then apply your preferred moisturizers.

  • Maintain moisture in your lips by regularly applying lip balm. The best is still applying petroleum jelly on lips and leaving it overnight.




Friday, January 13, 2012

How to find the given number is little endian or big endian?

#include <stdio.h>
int main()
{
  unsigned int n = 1;
  char *p;
  p = (char*)&n;
  if (*p == 1)
  printf("Little Endian\n");
  else if (*(p + sizeof(int) - 1) == 1)
  printf("Big Endian\n");
  else
  printf("Surprise output!!!!\n");
  return 0;
}

Write a macro for set and reset, swap.

#define SET_BIT( _X_, _NO_ ) ( 1<<(_X_-1)) | _NO_
#define RESET_BIT( _X_, _NO_ ) ~( ( 1<<(_X_-1) ) ) & _NO_
#define SWAP_BIT( _X_, _NO_ ) ( 1<<(_X_-1)) ^ _NO_

Preemptive Scheduler & Priority Inverse

Preemptive Scheduler
A scheduler that may switch between threads at any time.


 Priority Inverse
A situation where a low-priority task holds a resource which a higher-priority task is waiting for.

What is preemption?

The act of suspending the execution of one thread and starting (or resuming) another. The suspended thread is said to have been "preempted" by the new thread.

Message Queue, Semaphore and Mutex

Message Queue
Tasks communicate with each other using message queues.

Semaphore and Mutex
Semaphore / Mutex is mainly used for synchronization between tasks.

Mutex(mutual-exclusion locks) is nothing but a semaphore which semaphore-wait and semaphore-signal should be done with in a task. Mutexes  are used to implement critical sections and protect shared mutable data structures against concurrent accesses.

Semaphore Services
  • Way to synchronize multiple tasks
  • to ensure mutual exclusion
  • Control access to a shared resource

Timeslice & Timeslice Termination

Timeslice
In a multitasking environment, if more than one task having same priority will be executed simultaneously in a short interval of time. This is called Time slice. 

Timeslice Termination
A task needs to voluntarily give up control of the CPU so that another task at the same priority can execute, that is, terminate the current timeslice. This is achieved with the functions:
void task_reschedule (void);
void task_yield (void);

Interrupts

Provide a away for external events to control the CPU. CPU will stop executing the current task and start executing the interrupt handler for that interrupt. Interrupts can be prevented from interrupting the task by using the interrupt_mask() or interrupt_mask_all() functions.

The kernel scheduler

The kernel scheduler can be prevented from preempting or timeslicing the current task, by using the following pair of functions:
void task_lock (void);
void task_unlock (void);

Three states of CPU to schedule

Ready - waiting to run (in ready list)
Running - process (thread or task) is utilizing the processor to execute instructions
Blocked - waiting for resources (I/O, memory, critical section, etc.)

Four main tasks of OS

  • Process Management
        Process creation
        Process execution control
        Interaction of the process with signal events
        Process monitoring
        CPU allocation
        Process termination
  • Interprocess Communication
        Synchronization and coordination
        Deadlock and Livelock detection
        Process Protection
        Data Exchange Mechanisms
  • Memory Management
        Services for file creation, deletion, reposition and protection
  • Input/Output Management
        Handles requests and release subroutines for a variety of peripherals and read, write and reposition 
        programs

Hard real-time & Soft real-time

Hard real-time
Realtime applications can be classified as either hard or soft realtime. Hard realtime applications require a response to events within a predetermined amount of time for the application to function properly. If a hard realtime application fails to meet specified deadlines, the application fails. While many hard realtime applications require high-speed responses, the granularity of the timing is not the central issue in a hard realtime application.

An example of a hard realtime application is Avionic control system where a late response will result fail in operation.

Soft real-time
Soft realtime applications do not fail if a deadline is missed. Some soft realtime applications can process large amounts of data or require a very fast response time, but the key issue is whether or not meeting timing constraints is a condition for success.

An example of a soft realtime application is an hotel reservation system where an occasional delay is tolerable, but unwanted.

RTOS

RTOS is specifically designed for real time applications. It should respond the external events with in a short and predictable time frame. The following devices are using RTOS,
  • Mobiles
  • Set top box
  • Industrial robots
  • Spacecraft
Examples for RTOS,
  •     RTLinux
  •     VxWorks
  •     ST Lite

C Interview Questions

  1.     What does static variable mean?
  2.     What is a pointer?
  3.     What is a structure?
  4.     What are the differences between structures and arrays?
  5.     In header files whether functions are declared or defined?
  6.     What are the differences between malloc() and calloc()?
  7.     What are macros? what are its advantages and disadvantages?
  8.     Difference between pass by reference and pass by value?
  9.     What is static identifier?
  10.     Where are the auto variables stored?
  11.     Where does global, static, local, register variables, free memory and C Program instructions get stored?
  12.     Difference between arrays and linked list?
  13.     What are enumerations?
  14.     What is the keyword 'extern' means?
  15.     What are register variables? What are the advantage of using register variables?
  16.     What is the use of typedef?
  17.     What is recursion?
  18.     What are the different storage classes in C?
  19.     What is difference between Structure and Unions?
  20.     What the advantages of using Unions?
  21.     What are the advantages of using pointers in a program?
  22.     What is the difference between Strings and Arrays?
  23.     what is a NULL Pointer? Whether it is same as an uninitialized pointer?
  24.     What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
  25.     What does the error 'Null Pointer Assignment' mean and what causes this error?
  26.     How can we check whether the contents of two structure variables are same or not?
  27.     How are Structure passing and returning implemented by the complier?
  28.     How can we read/write Structures from/to data files?
  29.     What is the difference between an enumeration and a set of pre-processor # defines?
  30.     What are bit fields? What is the use of bit fields in a Structure declaration?
  31.     Which bit wise operator is suitable for checking whether a particular bit is on or off?
  32.     Which bit wise operator is suitable for turning off a particular bit in a number?
  33.     Which bit wise operator is suitable for putting on a particular bit in a number?
  34.     Which bit wise operator is suitable for checking whether a particular bit is on or off?
  35.     Write a program to compare two strings without using the strcmp() function.
  36.     Write a program to concatenate two strings.
  37.     Write a program to interchange 2 variables without using the third one.
  38.     Write programs for String Reversal without using string functions.
  39.     What are the advantages of using typedef in a program?
  40.     What is the difference between the functions memmove() and memcpy()?
  41.     How do you declare the following:
  •     An array of three pointers to chars
  •     An array of three char pointers
  •     A pointer to array of three chars
  •     A pointer to function which receives an int pointer and returns a float pointer
  •     A pointer to a function which receives nothing and returns nothing