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 remotehost.example.com
Debug ssh client
ssh -v -l jsmith remotehost.example.com
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
http://www.epistemesoft.com/Articles.aspx

Tuesday 28 July 2015

Programs to be explained in short

Programs to be explained in short
Q1.
main() 
{ 
int i=3; 
switch(i) 
{ 
default:printf("zero"); 
break; 
case 1: printf("one"); 
break;
more.................
Q2.
main() 
{ 
printf("%x",-1<<4); 
}
more..............
Q3. 
‪#‎define‬ uint16 unsigned short int 
main() 
{ 
uint16 i=65; 
printf("sizeof(i)=%d",sizeof(i)); 
}

Saturday 25 July 2015

Program to reverse a given string:

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

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)
More..
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
http://www.epistemesoft.com/Articles.aspx

Friday 24 July 2015

Precedence and Order of Evaluation and Programs

Precedence and Order of Evaluation examples
1.
/* hirarchy operations */ 
int k;
k=3/2*4+3/8+3 
--> 1*4+3/8+3 
--> 4+3/8+3
--> 4+0+3 
--> 7
2.
/* hirarchy operations */ 
g=big/2+big*4/big-big+abc/3; 
(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
More..
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
More..
Program to tell the given number is Even or Odd
‪#‎include‬ < stdio.h >
main() 
{ 
int number;
printf("Enter number\n"); 
scanf("%d", &number);
if(number % 2 == 0)
More..

Program to do sum of two values using functions
#include < stdio.h >
int sumfun(int numa, int numb);
main() 
{ 
int a = 10, b = 20; 
int sum;
sum = sumfun(a, b);
More..
All programs at below link
http://www.epistemesoft.com/Articles.aspx

Thursday 23 July 2015

Program to calculate Simple Interest

1. Program to print name four times using while loop

#include < stdio.h >

main()
{
int count = 1;

while(count <= 4 )
{

More..
2. Program to calculate Simple Interest

#include < stdio.h >

main()
{
int princ, time, rate;
int result;

printf("Enter Principal amount:\n");
scanf("%d",&princ);


More..
3. Program to calculate Simple Interest

#include < stdio.h >

main()
{
int princ, time, rate;
int result;

printf("Enter Principal amount:\n");
scanf("%d",&princ);
printf("Enter time:\n");

More..
4. Program to print Banner

#include < stdio.h >

main()
{
system("clear");
printf("WELCOME TO EPISTME SOFT\n");

More.
All programs at below link
http://www.epistemesoft.com/Articles.aspx

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
like filename.sh

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

1.#To print the user name
open a file with the name 1.sh as
vi 1.sh
copy the below line to that file
echo “Hello $USER”
save and quit the file with
Esc :wq
execute the file with the command
. 1.sh
output:
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"
output:
enter a value
1
enter b value
2
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 $@
Output:
./3.sh 1 2 3
1 2 3
3
1 2 3

4.#To find to numbers are equal or not using conditional statements
a=$1
b=$2
echo "a value: $a"
echo "b value: $b"
if [ $a -eq $b ]
then
          echo "$a and $b are equal.."
else
           echo "$a and $b are not equal.."
fi
Note: Here $1 and $2 are argv[1] and argv[2] respectively(command line arguments).
Output:
./4.sh 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 ]
then
             echo "file $1 is existed"
else
             echo "file $1 is not existed"
fi
output:
./5.sh 1.sh
file 1.sh existed
./5.sh 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))";;
esac
Output:
enter a value
1
enter b value
2
1:add
2:sub
3:mul
1
result: 3

7.#To perform arithmetic operations
a=10
b=20
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 ]
then
echo "a is equal to b"
fi 

if [ $a != $b ]
then
echo "a is not equal to b"
fi
Output:
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 PROTOCOL





  • 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.


COMMUNICATION:
  • 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.
BUS CHARACTERISTIC:

1.BUS NOT BUSY:
BOTH Data & Clock lines remain high.
2.START CONDITION:
A HIGH to LOW transition of SDA line while the SCL is high.
3.STOP CONDITION:
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.

5.ACKNOWLEDGE:
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