title: how to include linux kernel header files
body: <p>I am attempting some Linux kernel development. </p>
  
  <p>I have a problem in including a header file <strong>sched.h</strong>  (which exists in the path /usr/src/linux-3.12.26/kernel/sched, not in /usr/src/linux-3.12.26/include/linux ). </p>
  
  <p>But when I "<strong>sudo make -C  /usr/src/linux-3.12.26/  M=$(pwd)  modules</strong>" I got the  error <strong>"fatal error: kernel/sched/sched.h: doesn't exist"</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/percpu.h&gt;
  #include &lt;/usr/src/linux-3.12.26/kernel/sched/sched.h&gt;
  
  int __init init_current(void){
      int cpu_num=0;
      struct task_struct *p;
      for(cpu_num=0;cpu_num&lt;8;cpu_num++)
      {
       p=curr_task(cpu_num);
       printk(KERN_ALERT "current task on cpu %d is %d\n", cpu_num, p-&gt;pid);
      }
      return 0;
  }
  
  void __exit exit_current(void)
  {
     printk(KERN_ALERT "FINISHED！\n");
  }
  
  MODULE_LICENSE("GPL");
  module_init(init_current);
  module_exit(exit_current);
  </code></pre>
  
  <p>There may be some errors in the code. My intention is to get the current running process in different cores.            </p>
  
  <p>@Santosh A .Thanks for continuing concerning my puzzle.After I changed the Makefile in /usr/src/linux-3.12.26/(see my answer above，it may not be normative,but work ),the headers I include can be found.Then I get another problem. Here is my code:</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  //#include &lt;linux/sched.h&gt;
  #include &lt;linux/percpu.h&gt;
  #include &lt;sched/sched.h&gt;
  static int __init init_current(void){
  int cpu_num=0;
  extern struct task_struct *p;
  struct rq *q;
  extern struct rq * cpu_rq(int);
  for(cpu_num=0;cpu_num&lt;8;cpu_num++)
  {
   q=cpu_rq(cpu_num);
   p=q-&gt;curr;
   printk(KERN_ALERT "current task on cpu %d is %d\n", cpu_num, p-&gt;pid);
  }
  return 0;
  }
  
  static void __exit exit_current(void)
  {
   printk(KERN_ALERT "FINISHED！\n");
  }
  
  MODULE_LICENSE("GPL");
  module_init(init_current);
  module_exit(exit_current);
  </code></pre>
  
  <p>Here is error info:</p>
  
  <pre><code>/home/wison/code/current/current.c: In function ‘init_current’:
  kernel/sched/sched.h:539:23: error: expected identifier or ‘(’ before ‘&amp;’ token
   #define cpu_rq(cpu)  (&amp;per_cpu(runqueues, (cpu)))
                 ^
  /home/wison/code/current/current.c:11:28: note: in expansion of macro ‘cpu_rq’
   extern struct rq * cpu_rq(int);
  </code></pre>