title: any example of copy_from_user() ? kernel and userspace
body: <p>I am looking for copying PID value from User space to Kernel space, here is my code snaps.</p>
  <p>Kernel Module:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;asm/siginfo.h&gt;
  #include &lt;linux/rcupdate.h&gt;
  #include &lt;linux/sched.h&gt;
  #include &lt;linux/uaccess.h&gt;
  #include &lt;linux/signal.h&gt;
  
  MODULE_LICENSE (&quot;GPL&quot;);
  
  struct siginfo sinfo;
  pid_t pid;
  struct task_struct *task;
  
  int init_module() 
  {
      memset(&amp;sinfo, 0, sizeof(struct siginfo));
      sinfo.si_signo = SIGIO;
      sinfo.si_code = SI_USER;
      pid = 5218; // Everytime a new PID 
      // task = find_task_by_vpid(pid); I am also working on new and old version of UBUNTU so thats why this is here
      task = pid_task(find_vpid(pid), PIDTYPE_PID); 
      printk(&quot;%d .\n&quot;, task);
  
      if(task == NULL) {
          printk(&quot;Cannot find PID from user program\r\n&quot;);
          return 0;
      }
  
      send_sig_info(SIGIO, &amp;sinfo, task);
      return 0;
  }
  void cleanup_module () 
  {
      printk(KERN_ALERT&quot;\nGoodBye World\n\n&quot;);
  }
  </code></pre>
  <p>Userspace Code:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;string.h&gt;
  
  void signal_handler(int signum)
  {
      if (signum == SIGIO) printf(&quot;SIGIO\r\n&quot;); return;
  }
  
  int main()
  {
      int i = 1;
      signal(SIGIO, signal_handler);
      printf(&quot;My PID is %d.\n&quot;, getpid());
      
      while (i);
      return 0;
  }
  </code></pre>
  <p>Now, here I am always running user space program to get PID and then I always have to edit the pid variable in Kernel module.</p>
  <p>I found one way to access information from user space into Kernel space and vice-versa (i.e., using <code>copy_from/to_user()</code> )</p>
  <p>But I am unable to understand either of them for getting a PID from user space, I have to make file in <code>/dev</code> directory and should apply all the required functions for just getting PID?</p>
  <p>Is there any other way? if not, then can anyone please help me to do this? I am new in c programming and playing with kernel module directly so its hard for me.</p>