Re: current task and pid assignment to a pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You are right i included <linux/sched.h> but not <asm/current.h> :(
Now it compiles all right. But there is still few doubts.

Why didn't the same code compile with including just <linux/sched.h>
and not <asm.current.h> when i use code like this ->

#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>

MODULE_LICENSE("GPL");
static int __init init(void)
{
       struct task_struct *p;
       p = current;
       printk(KERN_DEBUG "%u", p->pid);   <- gives error on this line.
       return 0;
}

static void __exit exit(void)
{
       printk(KERN_DEBUG "\nCurrent process is now in exit as %u", current->pid);
}
module_init(init);
module_exit(exit);

on the other hand if i use printk(KERN_DEBUG "%u", current->pid); in
the offending line i can compile it without any hiccups, why?


that is weird.
current is defined in asm/current.h and struct task_struct is declared
in sched.h. But sched.h internally includes asm/current.h. So, the
code should compile clean without explicitly including asm/current.h.

regards
Manish Regmi

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux