Retrieve information about the calling process from within a kernel module

From within a kernel module you can get information about the currently executing process using the current variable. current is of type struct task_struct. When a system call is executing (such as open, read, write, ioctl) the current process will be the caller.

For example to display the process id from within a read function:

	printk("%s: The calling process is \"%s\" (pid %i)\n",
				__FUNCTION__, current->comm, current->pid);

References:

J. Corbet, A. Rubini, & G. Kroah-Hartman. (2005). Linux Device Drivers, 3rd Ed. (p. 20)

 

Advertisements

4 thoughts on “Retrieve information about the calling process from within a kernel module

  1. Austin,
    when a socket send enters TCP/IP stack this command would print the pid of the calling process as we are in process context in kernel mode ,correct?

    However on the receive (RX)after irq and napi poll processing (I am assuming in both these case this command would generate an error) when the packet entires the stack will the packet flow still be soft irq context(i.e not associated with an y pid) till its received by the recv call?

    Thanks,
    Sritej

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s