title: Creating Kernel Thread using kernel_thread
body: <p>I am trying to create a kernel thread using Kernel_thread() as part of an assignment for school. I am coding based on the professors example that I believe is outdated. I am getting errors and I have no idea how to proceed.</p>
  
  <p>What I am doing:</p>
  
  <pre><code>mypid = kernel_thread(myFirstFunctionOne, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); 
  </code></pre>
  
  <p>where myFirstFunctionOne is defined as:</p>
  
  <pre><code>static int myFirstFunctionOne(void *unused){
  struct task_struct *tsk = current;
  
  spin_lock_irq(&amp;current-&gt;sighand-&gt;siglock);
  flush_signal_handlers(current, 1);
  spin_unlock_irq(&amp;current-&gt;sighand-&gt;siglock);
  
  strcpy(tsk-&gt;comm, "My name: m_k_t_do_something_1");
  set_task_state(tsk, TASK_RUNNING);
  printk(KERN_NOTICE "My name: m_k_t_do_something_1 is about to be scheduled.\n");
  schedule();
  printk(KERN_NOTICE "My name: m_k_t_do_something_1 is now scheduled.\n");
  return 0;
  }
  </code></pre>
  
  <p>I am calling a function that just creates has that 1 line of code towards the end of Kernel_init, create_my_first_processes().</p>
  
  <pre><code>static int __ref kernel_init(void *unused)
  {
  int ret;
  
  kernel_init_freeable();
  /* need to finish all async __init code before freeing the memory */
  async_synchronize_full();
  free_initmem();
  mark_readonly();
  system_state = SYSTEM_RUNNING;
  numa_default_policy();
  
  flush_delayed_fput();
  
  rcu_end_inkernel_boot();
  
  create_my_first_processes();
  
  if (ramdisk_execute_command) {
      ret = run_init_process(ramdisk_execute_command);
      if (!ret)
          return 0;
      pr_err("Failed to execute %s (error %d)\n",
             ramdisk_execute_command, ret);
  }
  ...
  </code></pre>
  
  <p>This is the error I get when booting:</p>
  
  <p><a href="https://i.stack.imgur.com/GxmHh.jpg" rel="nofollow noreferrer">Kernel Panic</a></p>
  
  <p>Additional info: Running ubuntu on kernel 4.8.6</p>