My Tech notes: February 2009

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Friday, February 27, 2009

Linux Essential Shortcuts and Commands

Linux essential shortcuts and sanity commands

Switch to the first text terminal. Under Linux you can have several (6 in standard setup) terminals opened at the same time.
Switch to the nth text terminal.
Print the name of the terminal in which you are typing this command.

Switch to the first GUI terminal (if X-windows is running on this terminal).
Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1). On default, nothing is running on terminals
8 to 12, but you can run another server there.

(In a text terminal) Autocomplete the command if there is only one option, or else show all the available options.
THIS SHORTCUT IS GREAT! It even works at LILO prompt!

Scroll and edit the command history. Press to execute.

Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.

Scroll terminal output down.
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file /etc/X11/XF86Config (the first resolution starts on default, the largest determines the size of the "virtual screen"):
Modes "1024x768" "800x600" "640x480" "512x384" "480x300" "400x300" "1152x864"
(in X-windows) Change to the previous X-server resolution.

(in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally.

Useful Tips
I. If the output of a command scrolls too fast and you missed
something, press SHIFT+PAGEUP key to scroll backup.

II. You need not type the full name of a file or a command the TAB key
has an autocomplete feature in bash.
For example, let's say you have a file one_awefully_long_name_file
in your home directory, and want to look at its contents. You can say:
$ cat one[TAB]
The file name will be completed, provided no other file has
its name starting from 'one'. This tip can be applied any time you have
to enter a file-name or path-name at the command-prompt.
Similarly, you can also autocomplete commands also:
$ Xc[TAB]
will automatically insert:
$ Xconfigurator
As if that were not enough, pressing TAB twice will list all the
files/commands starting with that pattern. Try these:

$ cat a[TAB][TAB]

III. You can work in multiple terminals, running KDE in one and pure
console on another. Press CTRL+ALT+F2. See the login prompt? Usually
there will be six such virtual terminals. You can be using all of them.
Press CTRL+ALT+F-keys to switch. CTRL+ALT+F7 returns you to X if you
were originally using X Window like

Thursday, February 19, 2009

9 brain habits you did not realize you had

Brain is certainly the most amazing part of human body. It becomes more interesting when it does not work the way you expect it should. Psychology frequently establishes our intuitions about how human mind works, but it reveals a number of surprises as well…
clipped from

1) The maximum capacity of your short-term memory is seven.

short-term memory is seven

2) The most visible color is Chartreuse.

most visible color is Chartreuse

3) Subconscious is smarter than you.

Subconscious is smarter than you

4) There are two nervous systems.

There are two nervous systems

5) Brain is exceptionally bad at probability.

Brain is exceptionally bad at probability

6) Memory isn’t great either.

Memory isn’t great either

7) Depth is perceivable with one eye.

Depth is perceivable with one eye

8 ) Long-term memory closes up during sleep.

Long-term memory closes up during sleep

9) The Brain has an amazing instant playback feature.

Brain has an amazing instant playback feature

Brain is certainly the most amazing part of human body. It becomes more interesting when it does not work the way you expect it should. Psychology frequently establishes our intuitions about how human mind works, but it reveals a number of surprises as well…

 blog it

Wednesday, February 18, 2009

Useful Vi Editor Trick

Here is yet another Vi editor trick. At the Vi editor, we can edit multiple files by switching between them (With out opening another terminal)

$vi ex1.c ex2.c ex3.c

To switch one file to another use :n, :#e (With out exiting and opening the file)
like $vi ex1.c ex2.c ex3.c

:n Move forward to next file is the file list
:e# Toggle between the last two edited files
:rew Rewind file list and reopen first file in the list

Monday, February 16, 2009

Animated LILO The Linux Loader for SuSE Linux 7.2 or Animated boot-up screen

It's just something fun to do to add eye candy to your boot-up screen, if your tired of looking at the same old LILO prompt or boot-up screen every time you start your system.
Make your LILO boot screen more exciting with animated pictures! From the author's web page:

Since mid-2001, most Linux distributions include some patched versions of LILO (the LInux LOader) that support VGA or VESA graphical modes and make it possible to have a nice background image while booting. Starting with SuSE Linux 7.2, the SuSE distribution includes an interesting extension to LILO that allows a programmer to define some callback functions that are triggered when some events occur (key pressed, timeout, ...). It gives a much greater flexibility than the other extensions that are provided by most of the other Linux distributions, including the new graphical modes that have recently been added to the official version of LILO 22.x.

While testing the SuSE version of LILO and the helper program mkbootmsg, I was wondering if the timer callbacks together with the function that copies parts of the image to the screen could be used for creating animations. I quickly found out that it was indeed possible to enhance the boot screen with animations. Since my friends liked the results, I decided to share them on this web site. ... These animated boot screens have been tested with SuSE Linux 7.2 and 7.3. If you are using another distribution such as Debian, Red Hat, Mandrake or a custom set of packages, you will not get the expected results if you keep the version of LILO included in your distribution.
help page.

Sunday, February 15, 2009

Gear Up for GSoC 2009 Google Summe of Code The Google Summer of Code is a program designed to encourage college student participation
in open source development.
How does it work? Students submit project proposals to the organizations,
organizations rank the submissions (students paired with
mentor from open source community).Google allocates a given number of slots to each
organization, the students work all summer on their project in close mentored collaboration with that organization.
GSoC 2009 Timeline
March 9-13: Google will accept applications from open source projects.
March 13-17: Google program administrators review organization applications.
March 18: List of accepted mentoring organizations published on
March 23-April 3: Student applications acceptance period.
March 23: Student application period opens.
April 3: Student application deadline.
April 20: Accepted student proposals announced at
August 24: Final evaluation deadline.
September 3: Students can begin submitting required code samples to Google.

Google will provide a stipend of 5000 USD per accepted
student developer, of which 4500 USD goes to the student
and 500 USD goes to the mentoring organization.
• Accepted students in good standing with their mentoring
organization will receive a 500 USD stipend shortly after
coding begin.
• Students who receive passing mid-term evaluations will
receive a 2000 USD stipend shortly after the mid-term
• Students who receive passing final evaluations and who have
submitted their final program evaluations will receive a 2000
USD stipend and mentoring organizations will receive 500
USD shortly after the final evaluation deadline.
For more information visit
and apply!
Presentations on the Google Summer of Code Program

Thursday, February 12, 2009

Useful VI Commands For Linux Beginners Read on

useful vi commands for Linux beginners

1) To open two files in single window of vi editor
a) vi a.c
b) give the following command in vi editor to open b.c file
:sp b.c
c) Now vi editor contain two files in each half screen. TO switch
between two files use ctrl+ww.

2)Replacing a text
a) vi a.c
b) In a.c file, replace printf with printk using follwing command
This will replace only first occurrence of printf in each line.
The above command will replace all printf words in entire
file with printk.
The above command will ask confirmation.
This commamnd will replace in current line.

3)setting auto indentation:

In home directory create .exrc file add the following commands
:set nu
:set cindent

:set cindent will do indentation in C
4) To open a man page of a system call from vi editor
a) vi a.c
put the cursor at system call and press shift+k

5) commands:

G : to goto endline in vi
X : delete the character
J : To join two lines
DW : Delete the Word
/str : search down for string
?str : search up for string

Wednesday, February 11, 2009

Linux Command Line Most Used Shortcuts

Just sharing some of the command line shortcuts that I used and learnt; please share yours also.

1. To search in history or run previous commands
This is my most used shortcut. Hit Control-R and begin to type a string.

For example, type the following and hit Enter.

grep root /etc/passwd

Then hit Control-R and begin to type 'grep'.

(reverse-i-search)`gre': grep root /etc/passwd

When you see the original command listed, hit Enter to execute it. Alternatively, you can also hit the Right-Arrow to edit the command before running it.

Use -> ctrl + r and type the command, to go one more level back again hit ctrl + r, to edit the command before you execute use right key arrow.

2. To clear the present screen use -> ctrl + l (My discovery works on board also).

3. To edit previous command using vi commands -> set -o vi

Now you can use the Vi cw command to change the word in command.

4. Use of alias

alias ll='ls -l'
alias gohome='cd; ls'
If you want these custom aliases should be available each login, add them to your .bashrc.

You can refer to command line Bible got by chance

Features in a Nutshell

  • Understand the Linux desktop and various command-line parameters
  • Learn filesystem navigation, file handling, and the basics of bash shell commands
  • Write shell scripts to automate routine functions and reports
  • Harness nesting loops and structured commands
  • Monitor programs, master file permissions, and make queries
  • Run scripts in background mode and schedule jobs
  • Use sed, gawk, and regular expressions
  • Explore all alternate shells, including ash, tcsh, ksh, korn, and zsh


This is a linux command line reference for common operations at one place.

Tuesday, February 10, 2009

Effective Linux Kernel Search Trick here

I was wondering how to search a big kernel source for my specific keywords. Here I found out some of the combination.
Also there may be lot of ways to do the same things, that's the beauty of Linux.
Here we go
1. looking for MCS8142_SPI_FLASH in kernel
find . -name "*.c" | xargs grep "MCS8142_SPI_FLASH" | more
And here is the output.
./drivers/mtd/devices/mcs8142.c: mtd = mtd_concat_create(mtd_con,NO_OF_BANKS,"MCS8142

similar way you can grep for a particular struct from kernel source;
eg; find . -name "*.c" | xargs grep "struct jffs_node" | more

2. looking for MTD flag is set from .config file
here is the command
grep MTD .config | grep =y

Thursday, February 5, 2009

Five mysteries of the universe

The things that look so trivial, and so many times go unnoticed, when one begins to question them, it feels strange and maybe even threatening. Or exciting ?-)
clipped from

Five mysteries of the universe

there are scientific phenomena that defy explanation

1 The missing universe

Everything in the universe is either mass or energy, but there's not enough of either
96% of the cosmos is missing
"dark energy" and "dark matter"

2 Life

Next time you see a tree, ask yourself why that is alive when your wooden dining table is not.

3 Death

Here's the flip side: in biology, things eventually die, but there's no good explanation for it
switching genes on and off controls ageing, but if our theory is right, those switches shouldn't have survived natural selection

4 Sex

almost everything in biology uses sexual reproduction rather than asexual cloning
sex is a highly inefficient way to reproduce
At the moment, sex only seems to exist to give males some role in life.

5 Free will

Neuroscientists are almost convinced that free will is an illusion.
our brains allow us to think we are controlling our bodies, but our movements begin before we make a conscious decision to move.
 blog it

Wednesday, February 4, 2009

Kernel Programming Five Things to Keep in Mind before you start

Things to keep in mind for kernel programming
If you want to hack Linux kernel and do some programs, before you start keep some points in mind First and very basic point to make you feel relax with linux kernel, as,
kernel is nothing but a program as like other programs, which includes memory management, process scheduling, system management and all you need to work in.
1. In kernel space you do not have leisure of GLIBc library, ie you can not use printf also you have printk in kernel space.
2. Limited stack - you have limited stack space in kernel so do not make unnecessary variables declared, as tomorrow you may be going to add some new features. In user space you have almost unlimited stack so you will be little worried about how many variables you are using.
3. In kernel space no memory protection is there, as in user space if some memory corruption occurs kernel will trap and send signal. In kernel space there is no-one to trap memory corruption, it is like you are directly accessing the actual bit of physical memory. you have to be careful for oops messages.
4. In kernel space avoid using floting point operations. Floting point operations requires storing and restoring of floting point registers. Same is true that do not use floting point operations in Interrupt handler (sometimes favorite question in interview.) .
5. Take care of synchronization
Linux being preemptive kernel meaning if one process is working on one resource and interrupt comes, control of execution is given to interrupt and if interrupt handler also works on same resource then race condition occurs.
one has to take care of race conditions using spinlocks and semaphors.

Tuesday, February 3, 2009

Building Kernel for Embedded Linux with ARM board

I am giving general steps for building embedded linux for ARM board.
Building kernel for embedded linux

1. Download kernel
untar it using
bz2 format is more compressed than gz ;bz2 - tar -xvjx linux-x.x.x
GNU zip fromat gz - tar -xvzf linux-x.x.x

2. Configure kernel
Before you make build the kernel configure it. Linux kernel provides lot of features and almost all driver support.
All the features are not required for our embedded application. Select the required features, like processor type
if your board have USB support select the USB support. If your board have SATA support select the requried module.
one can configure linux kernel using
make config - text based configuration
make menuconfig - menu based configuration
make xconfig - x11 based configuration
make gconfig - gtk+ based configuration
If you are new to configuration you can start with make defconfig - creates default configuration and kept in
root folder as .config file. The flags which are set in this file are with CONFIG_USB.
Configuration comes as yes or no states. For modules it is tristate ie yes, no or module. In case of module yes
implies it is inbuilt in kernel. module implies it compiled as .ko and placed in respective directory. One can
attach these modules at runtime.
Make sure you have some root device (initial ramdisk, NFS) for your target system.

3. Build the kernel
Build the kernel using
no need to give compile option like make zImage if you are using linux 2.6 series.
This will compile the kernel using options selected, and compiled kernel image is kept in arch/arm/boot/zImage

4. Create the Filesystem
U-Boot does not support normal linux kernel images like zImage or Image (arch/arm/boot/),
you have to create an uImage file with the mkimage tool which encapsulates kernel image with header information,
CRC32 checksum, etc. More specifig "mkimage" encapsulates the images with a 64 byte header containing information about target architecture,
operating system, image type, compression method, entry points, time stamp, CRC32 checksums, etc.

The mkimage U-Boot tool is used to convert a standard kernel image into uImage format needed by bootm U-Boot
command. mkimage comes in source code with U-Boot distribution and it is built during U-Boot compilation

See U-Boot README file for more information.

Command to generate a compressed uImage file :

mkimage -T kernel -C none -a 0x8000 -e 0x8000 -d /arch/arm/boot/zImage scp_zimage

mkimage -A arch -O os -T type -C comp -a addr -e ep \
-n name -d data_file image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
5. Installing and loading the kernel image
To downloading a U-Boot image over the serial (console) interface, you must convert the image to S-Record format
using objcopy command. Instead load the kernel image over ethernet using TFTPBOOT command provided in U-boot.
In case of a Linux kernel image, the contents of the "bootargs" environment variable is passed to the kernel as
parameters. You can check and modify this variable using the "printenv" and "setenv" commands
change the bootargs as per your board configuration
on my board kernel image is stored in mtdblock3 so my options for bootargs is

setenv bootargs root=/dev/mtdblock3 rw rootfstype=jffs2 mem=64M@0x0

Mention filesystem type you are going to use, one can choose from ext2, ext3 and jffs2 filesystem type.
finally do bootmf to boot from flash,
These are very general steps and will require changes as per board design.

Monday, February 2, 2009

Good Linux PDF Books Links Collection

I was busy doing testing, so could not get time on exploring things around, now will be regular here,
Got one more good link collection which contains the linux related documents

One more link I like is Its collection of Free Computer Books Free online Books site buy online books free,This site contain free online books on computer science and software engineering. Books on C C++ Java web programming, Languages.

Do you know that you can change the color of you command prompt in windows, well how to get command prompt? its easy, click on start button on you windows and in run menu type cmd, hit enter, you are in DOS command prompt.
To change the color just type "color f2" as one example you can try out more combination.

Keep updating.

Reading is by no means a passive activity

'Reading a good book prepares you for real life. Scientists have found that, far from being a way to avoid reality" Reading a good book is also a good way to stimulate your mind, relax you, educate you and many other things. There is still nothing better than relaxing with a good book.
clipped from

Reading Bridget Jones could improve your love life, new study shows

Oliver Twist in the Howard Davies film from 1948
t's the news we've all been waiting for: reading a good book prepares you for real life. Scientists have found that, far from being a way to avoid reality
could make you better able to cope with similar situations in the real world
A brain-imaging study carried out by psychologists at Washington University
used functional magnetic resonance imaging to track brain activity as participants read short stories, finding that reading is by no means a passive activity
Instead, as participants read from a 1940s text about the daily activities of a young boy, activity in different brain regions increased depending on what was going on in the story
So, if the character in the book "pulled a light cord", brain activity increased in the frontal lobe region which controls grasping motions. As the character in the story
This study suggests that readers do mental simulation when they comprehend a story
 blog it