Do I need to include a library? Can anyone please elaborate in it?
I know is used to get the process id of the current task where is being called from
But I want to printk something with current->pid
printk("My current process id/pid is %d\n", current->pid);
...and is giving me an error
error: dereferencing pointer to incomplete type
I think you're looking for the getpid() system call. I don't know what
current
is though.You're looking for
#include <linux/sched.h>
. That's wheretask_struct
is declared.Your code should work. You are probably missing some header.
current
is a per-cpu variable defined inlinux/arch/x86/include/asm/current.h
(all the code is for the case of x86):current
points to the task running on a CPU at a given moment. Its type isstruct task_struct
and it is defined inlinux/include/linux/sched.h
:You can browse the code for these files in the Linux Cross Reference: