What is Data structure?

Data structure is a method of organizing large amount of data more efficiently so that any operation on that data becomes easy.

Data structures are divided into two types:
Linear Data Structures Non linear Data structures Linear Data Structure: In Linear data structure, data is organised in sequential order.
Ex: Arrays, Linked list, Stacks and Queues

Non Linear Data Structure: In Non Linear data structure, data is organised in random order.
Ex: Tree, Graphs

Interrupt Handling in Linux

What is Interrupt?

An interrupt (also known as an exception or trap) is an event that causes the CPU to stop executing the current program and start executing a special piece of code called an interrupt handler or interrupt service routine (ISR).

There are two different kinds of interrupts:

•Synchronous interrupt (Exception) produced by the CPU while processing instructions
•Asynchronous interrupt (Interrupt) issued by other hardware devices

Handling interrupts:
•Interrupts can occur at any time, the kernel tries to get it out of the way as soon as possible
•An interrupt can be interrupted by another interrupt
•There are regions in the kernel which must not be interrupted at all

Two different interrupt levels are defined:
•Maskable interrupts issued by I/O devices; can be in two states, masked or unmasked. Only unmasked interrupts are getting processed.
•Nonmaskable interrupts; critical malfunctions (f.e. hardware failure); always processed by the CPU.

Every hardware de…

Linux Kernel Modules

Linux kernel modules are pieces of code that can be loaded and unloaded from kernel on demand.

Kernel modules offers an easy way to extend the functionality of the base kernel without having to rebuild or recompile the kernel again. Most of the drivers are implemented as a Linux kernel modules. When those drivers are not needed, we can unload only that specific driver, which will reduce the kernel image size.

Kernel modules will have extension .ko
Kernel modules will operate on kernel space.
All Drivers are modules. Not all modules are drivers.

Kernel Modules Commands:
lsmod: To see list of modules that already loaded on system
insmod: To insert modules into kernel
modinfo: To display modules information
rmmod: To remove modules from kernel
How to Write Kernel Modules:
#include <linux/module.h> // included for all kernel modules #include <linux/kernel.h> // included for KERN_INFO #include <linux/init.h> // included for __init and __exit macros MODULE_LICENS…

Latest Kernel version

Current stable kernel version: 4.5.1

C program to reverse an array

#include int main() { int n, c, d, a[100], b[100]; printf("Enter the number of elements in array\n"); scanf("%d", &n); printf("Enter the array elements\n"); for (c = 0; c < n ; c++) scanf("%d", &a[c]); for (c = n - 1, d = 0; c >= 0; c--, d++) b[d] = a[c]; for (c = 0; c < n; c++) a[c] = b[c]; printf("Reverse array is\n"); for (c = 0; c < n; c++) printf("%d\n", a[c]); return 0; } This program reverses the array elements. For example if a is an array of integers with three elements such that a[0] = 1 a[1] = 2 a[2] = 3 Then on reversing the array will be a[0] = 3 a[1] = 2 a[0] = 1

C++; Singleton Design Pattern

Singleton is a creational design pattern.
Provide one and only instance of an object.
#include using namespace std;  class MySingleton  {        public: static MySingleton* iInstance;        public: static MySingleton* GetInstance();        private: MySingleton();  };  MySingleton* MySingleton::iInstance = NULL;  MySingleton::MySingleton()  {        cout << "Inside construtor ..." << endl;  }  MySingleton* MySingleton::GetInstance()  {       if ( iInstance == NULL )        {              iInstance = new MySingleton();        }       return iInstance;  } 

void main()  {       MySingleton* obj;       obj = MySingleton::GetInstance();  }

Useful linux commands

Vi Editor:

    x          Delete character at cursor
    X          Delete character before cursor
    Y or yy  Yank (copy) current line into "unnamed" storage buffer.
    p          Paste unnamed storage buffer after current line.
    P          Paste unnamed storage buffer before current line.
    r           Replace character
    R          Overwrite characters from cursor onward
    s          Substitute one character under cursor continue to insert
    S          Substitute entire line and begin to insert at beginning of line
    J           Join current and following line into one line

Use command: ":e filename"        Start new edit session on specified file name without closing current vi /        vim editor process.
Find/Replace:Example:       :%s/fff/rrrrr/  -   For all lines in a file, find string "fff" and replace with                                   string "rrrrr" for the first instance on a line.        :%s/fff/rrrrr/g -  For all lines in a f…