Chapter2 - Building and Running: The Hello World Module

 The Hello World Module The hello world is a very simple kernel module.  We will try to explore the same in this blog. I am assuming on your distribution (Debian, Ubuntu, Fedora, CentOS..etc) you have installed all the dependency packages, Kernel Source, and header files of the running kernel.  The sample hello.c kernel module can    #include <linux/module.h> #include <linux/init.h> MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("NARESH BHAT"); static int __init hello_init(void) {      printk(KERN_ALERT "Hello World!\n");      return 0; } static void __exit hello_exit(void) {      printk(KERN_ALERT "Good Bye, Cruel World!\n"); } module_init(hello_init); module_exit(hello_exit); When a module is loaded hello_init will be called and after unloading the kernel hello_exit function will be called by running kernel.  These are defined by module_init and module_exit kernel macros. Hence the module compiled version should match the running


  C TIPS and TECHNIQUES Data Presentation How will you represent -ve and +ve numbers in binary format ? Can you represent 0-127 +ve numbers and -1 to -128 -ve numbers ? 01111111 this is 127 the MSB is 0 in +ve series …… …….. 0000001  this is  1  0000000  this is  0 11111111  this is -1  the MSB is 1 in -ve series …. …... 1000000  this is -128 Using 2’s complement notation we can positive or negative values to each bit pattern. What are C’s basic data types can you explain ? C's basic data types are char, int, float, and double. Each size is machine dependent, but typical machines use 8 bits for a char, 32 bits for a float, and 64 bits for a double. The size of an int reflects the word size of the machine and is typically 16 or 32 bits. What are qualifiers for basic data types ? C provides long, short, and unsigned qualifiers for integer data types. A long is usually twice the size of an int on 16-bit machines, but long's and int's are ofte