//Save these files in one folder

//Program: hello.c

#include
#include
#include

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Huzaif Avez Sayyed");
MODULE_DESCRIPTION("This is a simple kernel program ");
static int myinit(void)
{
    printk(KERN_INFO,"HELLO WORKD\n");
    return 0;
}

static void mycleanup(void)
{
    printk(KERN_INFO,"GOOD BYE");
}

module_init(myinit);
module_exit(mycleanup);

//Makefile.txt

obj-m += hello.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

//OUTPUT

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$ make
make -C /lib/modules/4.4.0-72-generic/build M=/home/huzaif/Desktop/os/7 modules
make[1]: Entering directory '/usr/src/linux-headers-4.4.0-72-generic'
  CC [M]  /home/huzaif/Desktop/os/7/hello.o
In file included from include/linux/printk.h:6:0,
                 from include/linux/kernel.h:13,
                 from /home/huzaif/Desktop/os/7/hello.c:1:
/home/huzaif/Desktop/os/7/hello.c: In function ‘myinit’:
include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
include/linux/kern_levels.h:13:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational */
                   ^
/home/huzaif/Desktop/os/7/hello.c:11:9: note: in expansion of macro ‘KERN_INFO’
  printk(KERN_INFO,"HELLO WORKD\n");
         ^
/home/huzaif/Desktop/os/7/hello.c: In function ‘mycleanup’:
include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
include/linux/kern_levels.h:13:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational */
                   ^
/home/huzaif/Desktop/os/7/hello.c:17:9: note: in expansion of macro ‘KERN_INFO’
  printk(KERN_INFO,"GOOD BYE");
         ^
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/huzaif/Desktop/os/7/hello.mod.o
  LD [M]  /home/huzaif/Desktop/os/7/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-72-generic'

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$sudo insmod hello.ko

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$sudo dmesg | tail -1

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$sudo lsmod

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$sudo rmmod hello

huzaif@huzaif-Lenovo-Z51-70:~/Desktop/os/7$sudo dmesg | tail -1