Getting user process pid when writing Linux Kernel Module

user1592383 picture user1592383 · Aug 11, 2012 · Viewed 29.3k times · Source

How can I get the PID of the user process which triggered my Kernel module's file_operation.read routine (i.e., which process is reading /dev/mydev) ?

Answer

cnicutar picture cnicutar · Aug 11, 2012

When your read function is executing, it's doing so in the context of the process that issued the system call. You should thus pe able to use current, i.e. current->pid.