title: How to print linux kernel version number in kernel module
body: <p>I'm a noob to linux kernel programming and thought I'd be able to find the answer for this (since it seems really simple) but haven't had any luck yet. I need to make a linux kernel module that prints the version number of the kernel. The assignment requires that implement a module which displays this kind of message when loaded:</p>
  
  <p>"Hello Master. You are currently using Linux (version)", where (version) is the kernel version no.</p>
  
  <p>How can I do this? I tried using uname (<a href="http://man7.org/linux/man-pages/man2/uname.2.html" rel="nofollow">http://man7.org/linux/man-pages/man2/uname.2.html</a>) but when I include sys/utsname.h, I get a fatal error upon compiling with my makefile </p>
  
  <p>"Cannot open include file: 'sys/utsname.h': No such file or directory".</p>
  
  <p>Here is my module</p>
  
  <pre><code>#undef __KERNEL__
  #define __KERNEL__
  
  #undef __MODULE__
  #define __MODULE__
  
  #include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;sys/utsname.h&gt;
  
  struct utsname unameData;
  
  static int __init config_init(void)
  {
      uname(&amp;unameData);
      printk(KERN_INFO "Version number is %s\n", unameData.version);
      return 0;
  }
  
  static void __exit config_exit(void)
  {
      printk(KERN_INFO "config_exit executed with success\n");
      return;
  }
  
  module_init(config_init);
  module_exit(config_exit);
  
  MODULE_LICENSE("GPL");
  </code></pre>
  
  <p>Makefile</p>
  
  <pre><code>obj-m := config.o
  KDIR := /lib/modules/$(shell uname -r)/build
  PWD := $(shell pwd)
  
  all:
      $(MAKE) -C  $(KDIR) M=$(PWD) modules
  
  clean:
      $(MAKE) -C  $(KDIR) M=$(PWD) clean
  </code></pre>