Sunday, November 1, 2009
what is Mr Shah Birth date .. ?
Can you figure out what is the Date of Birth of Mr. Shah? Assume that the current year is 2000.
Thursday, October 29, 2009
"hello world" program without a main() function
This short article is on request of my friend Viswanath who wanted to run a C program without main() function on his computer .
I have done this on Ubuntu OS , with the simple Linux module , taken form guide :
"The Linux Kernel Module Programming Guide"
note : Aim of this article is not to teach you how to write a Linux kernel module , but to simply write a C program which runs on your Linux system and prints "Hello world", without use of main() function
only thing worth mentioning is "output" from "printk" goes to by default "/var/log/messages" , so your "hello world" would be printed their instead of terminal.
Step 1 :
create a file named hello-1.c with code given below :
/*
* hello−1.c − The simplest kernel module.
*/
#include
#include
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
//code ends here
Step 2 :
create a Makefile , with following code : (ie a file name Makefile )
//code starts here
obj-m += hello-1.o
all:
clean:
//code ends here
Step 3:
from terminal with sudo premission run following command :
$ make
you will see output like given below if successful :
hostname:~/lkmpg−examples/02−HelloWorld# make
make −C /lib/modules/2.6.11/build M=/root/lkmpg−examples/02−HelloWorld modules
make[1]: Entering directory `/usr/src/linux−2.6.11'
CC [M] /root/lkmpg−examples/02−HelloWorld/hello−1.o
Building modules, stage 2.
MODPOST
CC /root/lkmpg−examples/02−HelloWorld/hello−1.mod.o
LD [M] /root/lkmpg−examples/02−HelloWorld/hello−1.ko
make[1]: Leaving directory `/usr/src/linux−2.6.11'
hostname:~/lkmpg−examples/02−HelloWorld#
Step 4:
to load your module run command :
$ insmod ./hello-1.ko
now your module should be added in the module list of kernel. For checking this type following command :
$ cat /proc/modules
the first entry should be hello-1 , and thats your module.
Step 5:
to unload your module use following command :
$ rmmod hello-1
Step 6 :
wondering where did your printk " Hello world 1." and " Goodbye world 1."
went just and check the file :
$ cat /var/log/messages
towards the end you will find the two entries ,
Hello world 1.
Goodbye world 1.
Thats it.
Thanx for reading.
Note: if you really want to understand how all this worked please go through the article "The Linux Kernel Module Programming Guide" , which is easily available on web.
What does Compiling / upgrading Linux kernel mean ?
Through this short article i would like to share a concept which most of you might find very trivial , but i myself took sometime to understand it and wanted to share the same if some of you might have felt the same .
Before we proceed lets revise revise four basic concepts very quicky ...
What is an Operating System .. ?
Wikipedia says : The Linux kernel is an operating system kernel used by the Linux family of Unix Like Operating Systems. The Linux kernel was initially conceived and created by Finnish computer science student Linus Torvalds in 1991.
What is a Kernel .. ?
Wikipedia Says : In computing, the 'kernel' is the central component of most computer operating systems it can be thought of as the bridge between application and the actual data processing done at the hardware level. The kernel's responsibilities include managing the system's resources (the communication between hardware and software components).
What is Linux .. ?
Wikipedia Definition : Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel.
Definition from linux.org : Linux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of developers around the world. Developed under the GNU General Public License , the source code for Linux is freely available to everyone.
What is Linux Kernel .. ?
Wikipedia says : The Linux kernel is an operating system kernel used by the Linux family of Unix Like Operating Systems. The Linux kernel was initially conceived and created by Finnish computer science student Linus Torvalds in 1991.
So from above four question and answers its clear that :
Operating System and Kernel are not the same thing .
So get it clear .... Linux OS and Linux Kernel are not the same thing.
Therefore Ubuntu, fedora , Suse all these are operating Systems based on Linux kernel , started by our friend Linus Torvalds . So when you install any one of these you basically install a full blown Operating System ready to serve you , and this OS internally may be using any Linux Kernel release e.g 2.6.28 or 2.6.30 or .... any other .. they just keep coming with modifications and updates .
Now suppose you have installed a Ubuntu OS on your system with default kernel release 2.6.28 , now after few days you go to www.kernel.org and find the latest kernel release is 2.6.30 , which is ofcourse supposed to be better that 2.6.28 in one or the other aspect.
So now you want to use latest kernel , so now you download the lastest kernel code and " compile that C program code" .
note: to know how to comile kernel code serach web or better look for article written by me : compiling linux kernel 2.6.30
So now after rebooting the system , with new kernel , what difference do you see ....
Practically nothing : Your user name , password are still the same , your wallpaper is still the same , your user setting reamains the same .
Only thing that had changed and is not visible is "Linux Kernel" version , running in background and managing all your resources and processes .
You can check the running version by running following shell command :
$ cat /proc/version
so in the end , just keep in mind Linux based OS and Linux Kernel are two completely different things ... and changing them is also different.
Like you can change your OS from Ubuntu to fedora and both of the may still be using same Linux Kernel 2.6.30 .
Thanx for reading .
How does a C Program Work/Execute
A Text Segement (also known a Code Segment) , which contains a block of machine instructions .
Data Segment , which is a block of Static Variables .
Stack Segment , which represents the stack which is used while program is in execution .
Sunday, October 18, 2009
Thoughts Of MY OWN ... !
- Samarth Gupta
overcome your fears ... they are not that dangerous as they seem to be ... !
- Samarth Gupta
Three people can never be Best Friends to each other ...
- Samath Gupta
... I have Dreams ... and I am ready to fight for them ..... !
- Samath Gupta
..... In the end you have only Three true Friends .... your Mother .... Father ... and MONEY ... !
- Samath Gupta
Every one wants to hear the TRUTH .... only condition is it should not be about Himself ... !
- Samarth Gupta
Never answer a Question .... which is not addressed to you .... !
- Samarth Gupta
Got Bored of EARTH .... planning to go back Home .... !
- Samarth Gupta
If humans, the most intelligent of all beings can't understand each other then wats the point
- Sandeep Bhaskar
my opinion about above thought :
humans understand each other very well ... the point is they dont like what they have understood .... !
- Samarth Gupta
Wednesday, September 23, 2009
Enjoy Your Coffee....
A group of alumni, highly established in their careers got together to visit old university professor. Conversation soon turned into complaints about stress in work and life.
Offering his guest coffee, professor went to the kitchen and brought a large pot of coffee and assortment of cups- porcelain, plastic, glass, crystal. Some plain looking, some expensive and some exquisite, telling them to help themselves to hot coffee.
When all the student had a cup of coffee in hand professor said-
If you noticed, all the nice looking expensive cups were taken up leaving behind the plain and cheap ones. It is normal for you to want only the best for yourself But that is the source of your problem and stress.
What all of you wanted was coffee, not the cup, but you consciously want for the best cup and were eyeing each other’s cup.
Now if life is coffee, than jobs, money and position in society are the cups. They are just tools to hold Life, but the quality of Life doesn’t change. Sometimes by concentrating only on the cup we fail to enjoy the coffee in it.
So don’t let the cups drive you….
Enjoy the coffee instead.
Tuesday, September 22, 2009
printf() interview question ....
Look at the code below.
void main()
{
if(X)
{
printf("Hello");
}
else
{
printf(" World");
}
}
What should X be replaced with inorder to get the output as "Hello World"?
About Me
- Samarth
- Hi Friends, I am Samarth currently pursuing my Masters degree in Information Technology from International Institute of Information Technology ,Bangalore .