Friday 31 July 2015

UNIX/LINUX commands

1. tar command examples
Create a new tar archive.
$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
$ tar xvf archive_name.tar
View an existing tar archive.
$ tar tvf archive_name.tar

2. grep command examples
Search for a given string in a file (case in-sensitive search).
$ grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
Search for a given string in all files recursively
$ grep -r "ramesh" *

3. find command examples
Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"
Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty

4. ssh command examples
Login to remote host
ssh -l jsmith
Debug ssh client
ssh -v -l jsmith
Display ssh client version
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

5. sed command examples
When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename
Print file content in reverse order
$ sed -n '1!G;h;$p' thegeekstuff.txt
Add line number for all non-empty-lines in a file
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

see more at below link

Tuesday 28 July 2015

Programs to be explained in short

Programs to be explained in short
int i=3; 
case 1: printf("one"); 
‪#‎define‬ uint16 unsigned short int 
uint16 i=65; 

Saturday 25 July 2015

Program to reverse a given string:

#‎include‬ < stdio.h > 
#include < string.h >
void ReverseString (char *String); 
char string[] = "Episteme Soft India";

One line Interview Questions on Linux Signals and Linux Process

Signal: A signal tells our program that some event has occurred
SIGINT: Interrupt signal from terminal (ctrl-c)
SIGTSTP: Stop signal from terminal (ctrl-z)
SIGCHLD: A child process has stopped or terminated

Send Signal to Process: int kill(pid_t pid, int sig)
Send Signal to Groups: int kill(pid_t gid, int sig)
One line Interview Questions on Linux Process
Process: An instance of running program
Context switching: Multiple processes run “concurrently” by time slicing
RTOS: Preemptive scheduler of OS
Process vs Threads: Threads are logical flows that run in the context of a single process.
PID: A process has its own, unique process ID: pid_t getpid();
More at below link

Friday 24 July 2015

Precedence and Order of Evaluation and Programs

Precedence and Order of Evaluation examples
/* hirarchy operations */ 
int k;
--> 1*4+3/8+3 
--> 4+3/8+3
--> 4+0+3 
--> 7
/* hirarchy operations */ 
(abc=1.5 , big=3 ,assume g is float) 
g = 3/2+3*4/3-3+1.5/3 
= 1+12/3-3+1.5/3
Precedence and Order of Evaluation
The rules for precedence and associativity of all operators. Operators on the same line have the same precedence; rows are in order of decreasing precedence, so, for example, *, /, and % all have the same
Program to tell the given number is Even or Odd
‪#‎include‬ < stdio.h >
int number;
printf("Enter number\n"); 
scanf("%d", &number);
if(number % 2 == 0)

Program to do sum of two values using functions
#include < stdio.h >
int sumfun(int numa, int numb);
int a = 10, b = 20; 
int sum;
sum = sumfun(a, b);
All programs at below link

Thursday 23 July 2015

Program to calculate Simple Interest

1. Program to print name four times using while loop

#include < stdio.h >

int count = 1;

while(count <= 4 )

2. Program to calculate Simple Interest

#include < stdio.h >

int princ, time, rate;
int result;

printf("Enter Principal amount:\n");

3. Program to calculate Simple Interest

#include < stdio.h >

int princ, time, rate;
int result;

printf("Enter Principal amount:\n");
printf("Enter time:\n");

4. Program to print Banner

#include < stdio.h >


All programs at below link

Saturday 11 July 2015

Shell Scripting

A shell script is a computer program designed to be run by the Unix shell, a command line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.In the simplest terms, a shell script is a file containing a series of commands. The shell reads this file and carries out the commands as though they have been entered directly on the command line.

The file name should have the extension .sh

To Execute the file we have to give execution
     chmod +x
to execute
Or we can execute the file without changing the permissions, like
Let's see some examples on the shellscripting

1.#To print the user name
open a file with the name as
copy the below line to that file
echo “Hello $USER”
save and quit the file with
Esc :wq
execute the file with the command
Hello episteme

2.#to take the input from the user and print the output
echo "enter a value"
read a
#read -t 2 a :to wait for 2 sec
echo "enter b value"
read b
echo "a value: $a"
echo "b value: $b"
enter a value
enter b value
a value:1
b value:2

3.programming with command line arguments
#to print command line arguments
echo $*
#to print number of command line arguments
echo $#
#to print command line arguments
echo $@
./ 1 2 3
1 2 3
1 2 3

4.#To find to numbers are equal or not using conditional statements
echo "a value: $a"
echo "b value: $b"
if [ $a -eq $b ]
          echo "$a and $b are equal.."
           echo "$a and $b are not equal.."
Note: Here $1 and $2 are argv[1] and argv[2] respectively(command line arguments).
./ 1 2
a value: 1
b value: 2
1 and 2 are not equal..

5.#to check whether a file is existed or not
if [ -e $1 ]
             echo "file $1 is existed"
             echo "file $1 is not existed"
file existed
./ hi
file hi is not existed

6.#shell script to implement arithmetic operations using switch statement
echo "enter a value"
read a
echo "enter b value"
read b
echo -e "1:add\n2:sub\n3:mul\n"
read c
case $c in
1)echo "result: $(($a + $b))";;
2)echo "result: $(($a - $b))";;
3)echo "result: $(($a * $b))";;
enter a value
enter b value
result: 3

7.#To perform arithmetic operations
val=`expr $a + $b`
echo "a + b : $val" 

val=`expr $a - $b`
echo "a - b : $val" 

val=`expr $a \* $b`
echo "a * b : $val" 

val=`expr $b / $a`
echo "b / a : $val" 

val=`expr $b % $a`
echo "b % a : $val" 

if [ $a == $b ]
echo "a is equal to b"

if [ $a != $b ]
echo "a is not equal to b"
a + b : 30
a - b : -10
a * b : 200
b / a : 2
b % a : 0
a is not equal to b

Tuesday 7 July 2015

Linux Interview Questions

1) What is Linux?
Linux is an operating system based on UNIX, and was first introduced by Linus Torvalds. It is based on the Linux Kernel, and can run on different hardware platforms manufactured by Intel, MIPS, HP, IBM, SPARC and Motorola. Another popular element in Linux is its mascot, a penguin figure named Tux.

2) What is Linux Kernel?
The Linux Kernel is a low-level systems software whose main role is to manage hardware resources for the user. It is also used to provide an interface for user-level interaction.

3) What is LILO?
LILO is a boot loader for Linux. It is used mainly to load the Linux operating system into main memory so that it can begin its operations.

4) What is BASH?
BASH is short for Bourne Again SHell. It was written by Steve Bourne as a replacement to the original Bourne Shell (represented by /bin/sh). It combines all the features from the original version of Bourne Shell, plus additional functions to make it easier and more convenient to use. It has since been adapted as the default shell for most systems running Linux.

5) What is a swap space?
A swap space is a certain amount of space used by Linux to temporarily hold some programs that are running concurrently. This happens when RAM does not have enough memory to hold all programs that are executing.

6) What is the basic difference between BASH and DOS?
The key differences between the BASH and DOS console lies in 3 areas:
- BASH commands are case sensitive while DOS commands are not;
- under BASH, / character is a directory separator and \ acts as an escape character. Under DOS, / serves as a command argument delimiter and \ is the directory separator
- DOS follows a convention in naming files, which is 8 character file name followed by a dot and 3 character for the extension. BASH follows no such convention.

7) What is CLI?
CLI is short for Command Line Interface. This interface allows user to type declarative commands to instruct the computer to perform operations. CLI offers an advantage in that there is greater flexibility. However, other users who are already accustom with using GUI find it difficult to remember commands including attributes that come with it.

8) What is GUI?
GUI, or Graphical User Interface, makes use of images and icons that users click and manipulate as a way of communicating with the computer. Instead of having to remember and type commands, the use of graphical elements makes it easier to interact with the system, as well as adding more attraction through images, icons and colors.

9) How can you find out how much memory Linux is using?
From a command shell, use the “concatenate” command: cat /proc/meminfo for memory usage information.

10) What are symbolic links?
Symbolic links act similarly to shortcuts in Windows. Such links point to programs, files or directories. It also allows you instant access to it without having to go directly to the entire pathname.

11) What are hard links?
Hard links point directly to the physical file on disk, and not on the path name. This means that if you rename or move the original file, the link will not break, since the link is for the file itself, not the path where the file is located.

12) Are drives such as hard drive and floppy drives represented with drive letters?
No. In Linux, each drive and device has different designations. For example, floppy drives are referred to as /dev/fd0 and /dev/fd1. IDE/EIDE hard drives are referred to as /dev/hda, /dev/hdb, /dev/hdc, and so forth.

13) What is the maximum length for a filename under Linux?
Any filename can have a maximum of 255 characters. This limit does not include the path name, so therefore the entire pathname and filename could well exceed 255 characters.

14)What are filenames that are preceded by a dot?
In general, filenames that are preceded by a dot are hidden files. These files can be configuration files that hold important data or setup info. Setting these files as hidden makes it less likely to be accidentally deleted.

Embedded Systems Training

Saturday 4 July 2015


  • I2C is a MULTI MASTER SERIAL BUS i.e. more than one device capable of controlling the bus can be connected to it. It was invented by PHILIPS & stands for Inter-Integrated Circuit.
  • In I2C only two bi-directional lines Serial Data (SDA) & Serial Clock (SCL) are required to carry information between the devices connected to the bus.
  • Each I2C device is recognized by a unique 7-bit address. The device that initiates the communication is called MASTER.
  • The master controls the clock signal. Whereas the device being addressed by the Master is called as SLAVE.
  • Generation of clock signals on the I2C-bus is always the responsibility of master devices; each master generates its own clock signals when transferring data on the bus.
Data Transmission through I2C Bus:
Data on the I2C bus can be transferred in three modes:
1) Standard Mode: 100kbps.
2) Fast Mode: 400kbps
3) High Speed Mode: 3.4Mbps.
 The maximum number of nodes is obviously limited by the address space, and also by the total bus capacitance of 400 pf.

  • The master begins the communication by issuing the START condition followed by 7- bit unique address/Control Byte of the device it wants to access.
  • The eighth bit after the start specifies if the slave is now to receive (0) or to transmit (1). 
  • After reciving the address all IC's on the I2C bus will compare with their own address & if the address does not match, it will wait till a STOP is received.
  • If address matches a ACKNOWLEDGE signal is generated by the Slave.

  • Following receipt of the slave’s address acknowledgment, the master continues with the data transfer. If a write operationhas been ordered, the master transmits the remaining data, with the slave acknowledging receipt of each byte.
  • If the master has ordered a read operation, it releases the data line and clocks in data sent by the slave. After each byte is received, the master generates an acknowledge condition on the bus.
  • The acknowledge is omitted following receipt of the last byte. The master terminates all operations by generating a stop condition on the bus. The master may also abort a data transfer at any time by generating a stop condition.

BOTH Data & Clock lines remain high.
A HIGH to LOW transition of SDA line while the SCL is high.
A LOW to HIGH transition of SDA line while the SCL is high.
4.DATA VALID:During Data transfer, the data on must be changed during the LOW period of the clock signal i.e. the data line must remain stable whenever the clock line is HIGH. Any change in data line while clock is HIGH will be interpreted as START or STOP condition.

Each device when addressed to has to generate an acknowledge signal after the reception of each byte. The master generated an extra clock pulse which is associated with the ACKNOWLEDGE bit. The device that acknowledges pulls down the SDA line during the acknowledge clock pulse.
Embedded System Training