To find what kernel is running:
  prompt> uname -a
  Linux franco.cinci.rr.com 3.10.9-200.fc19.i686 #1 SMP Wed Aug 21 20:48:34...

-------------------------------------------------------------------------

Check that the kernel source directory exists 
(note: 3.13.0-12-generic may be different on your machine, use 'uname -r'
 to determine what it is on your machine): 
  prompt> cd /lib/modules/3.13.0-12-generic/
  prompt> ls
  build@    modules.alias        modules.builtin      modules.order
  extra/    modules.alias.bin    modules.dep          modules.softdep
  kernel/   modules.builtin.bin  modules.devname      modules.symbols
  source@   modules.dep.bin      modules.drm
  updates/  modules.symbols.bin  modules.modesetting
  vdso/     modules.block        modules.networking
  prompt> ls build/
  arch/     firmware/  ipc/     Makefile  scripts/   usr/        Module.symvers
  block/    fs/        Kconfig  mm/       security/  virt/
  crypto/   include/   kernel/  net/      sound/     vmlinux.id
  drivers/  init/      lib/     samples/  tools/     System.map

-------------------------------------------------------------------------

Check the Makefile associated with a module source:
  # obj-m:
  #   specifies object files which are built as loadable kernel modules.
  # make modifiers:
  #  -C dir:
  #     Change  to directory dir before reading the makefiles or doing any-
  #     thing else.  We need to compile in root directory of kernel source.
  #   M=dir:
  #     The path to the source file(s) of the kernel module to be built
  obj-m := tester_1.o

  KVERSION := $(shell uname -r)
  KDIR := /lib/modules/$(KVERSION)/build
  PWD := $(shell pwd)

  default:
	make -C $(KDIR) M=$(PWD) modules  # line begins with tab

  clean:
	make -C $(KDIR) M=$(PWD) clean    # line begins with tab

-------------------------------------------------------------------------

(almost) essential elements of a kernel module:

  #include <linux/module.h>

  int init_module(void) {
     printk(KERN_INFO "tester 1: Module loaded successfully\n");
     return 0;
  }

  void cleanup_module(void) {
     printk(KERN_INFO "tester 1: Module unloaded successfully\n");
  }

where printk - is the special print for kernel space
  KERN_INFO - output goes to /var/log/messages, check with dmesg
  KERN_EMERG - output goes to all open consoles, also check with dmesg
init_module is invoked on load
cleanup_module is invoked on unload

-------------------------------------------------------------------------

To compile a kernel module:
  prompt> make
  make -C /lib/modules/3.11.0-12-generic/build M=~/Downloads modules
  make[1]: Entering directory `/usr/src/kernels/3.10.10-200.fc19.i686'
    CC [M]  /home/franco/Downloads/tester_1.o
    Building modules, stage 2.
    MODPOST 1 modules
    CC      /home/franco/Downloads/tester_1.mod.o
    LD [M]  /home/franco/Downloads/tester_1.ko
  make[1]: Leaving directory `/usr/src/kernels/3.10.10-200.fc19.i686'

To compile several modules, modify the Makefile (example):
  obj-m := tester_1.o
  obj-m += tester_2.o 
  obj-m += tester_3.o 

-------------------------------------------------------------------------

To load, use, unload a module:
  prompt> lsmod | grep tester
  (nothing - the module is not loaded)
  prompt> sudo insmod tester_1.ko
  dmesg
  [  490.505166] tester 1: Module loaded successfully
  prompt> lsmod | grep tester
  tester_1               12394  0
  prompt> sudo rmmod tester_1
  dmesg
  [  490.505166] tester 1: Module loaded successfully
  [  632.650328] tester 1: Module unloaded successfully
  prompt> lsmod | grep tester
  (nothing)

-------------------------------------------------------------------------

Interface between user and a running module (via /proc filesystem):
  see tester_4.c for example and instructions

-------------------------------------------------------------------------