Thursday, 27 August 2015

'C' multi-buffer tokeniser (reentrant version)


char *strtok_r(char *str, const char *delim, char **saveptr);

The strtok_r() function is a reentrant version strtok(). The saveptr argument is a pointer to a char * variable that is used internally by strtok_r() in order to maintain context between successive calls that parse the same string.

strtok_r() is used almost exactly as strtok() except with additional last parameter char ** saveptr is passed. This is used internally, to save of buffer state.


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


int main() {
  char buffer1[50];
  char buffer2[50];
  char *save1, *save2, *token1, *token2;

  strcpy(buffer1, "A-B-C-D");
  strcpy(buffer2, "1:2:3:4");

  token1 = strtok_r(buffer1, "-", &save1);
  token2 = strtok_r(buffer2, ":", &save2);

  while(token1 != NULL ||
        token2 != NULL) {
     printf("[%s%s]\n", token1, token2);
     token1 = strtok_r(NULL, "-", &save1);
     token2 = strtok_r(NULL, ":", &save2);
  }
  return 0;

}


Wednesday, 26 August 2015

Writing Linux Kernel module

  lsmod – List all loaded kernel modules




Sample kernel module

hello_world.c module in 'C'
 


Compiling kernel module
 
make -C /lib/modules/<`uname -r`>/build M=<path_to_hello_world.c file> modules
 
#on successful compilation : hello_world.ko file will be generated

 Adding /inserting module 

 # loading the module
insmod hello_world.ko

# checking whether module is loaded.
dmesg |grep

# checking using lsmod
lsmod | grep hello

Wednesday, 29 April 2015

shell - Indirect variable references


KSH
       i = 10
       var_ref=variable_sequence _$i
       eval  pointer_to_val=\$$var_ref

BASH
      i = 10
       var_ref=variable_sequence _$i
       pointer_to_val=${!var_ref}

Friday, 5 July 2013

Radar slant and blind range

Slant range:

Slant range is line of sight distance between radar antenna and flying aircraft.

The distance is determined by measuring the time between propagating electromagnetic waves and receiving it back.

Electromagnetic waves velocity is 3 X 108 m / s (speed of light)
Slant range (in meter) = Velocity * time taken / 2

Radar Blind range:

This is minimal measuring distance for any given radar, this is because radar receiver is switch-off until is  transmission is completed.

Sunday, 15 May 2011

Nonlinear data structures tree vs graph



Tree - is a hierarchical data structure of nodes.
Nodes are usually structured in the parent-child manner. However line joining two nodes has no significance.



Graph - similar to the tress except that line joining the nodes is also important (generally known as edge). In graph a edge could represent anything (time, distance etc possibilities are endless).  i.e. In a train map line may represent the distance or time.

In plain words a scaled train map in the example of graph whereas same train map without scaling is the example of a tree.



Moreover edges are broadly categorized in the two categories as follows:
            1) Bi-directional graph, i.e. edges is bidirectional.
            2) Unidirectional graph, ugh just opposite to bi-directional.
 

Friday, 6 May 2011

Hello World!

Hello from Umesh Mittal. This blog will contain some of my technical thoughts and learnings, as well as some personal ones.

Total Pageviews

Popular Posts