Reputation: 555
How can i get and show name and PID for current proccess in a Linux kernel module? My code :
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
MODULE_DESCRIPTION("Afiseaza PID si numele executabilului");
MODULE_AUTHOR("ololo");
MODULE_LICENSE("FREE");
static int print_on_init(void)
{
struct task *cur_task;
cur_task = get_current();
printk(KERN_DEBUG, "Hello!\n");
return 0;
}
static int print_on_exit(void)
{
printk(KERN_DEBUG, "Goodbye!\n");
}
module_init(my_hello_init);
module_exit(hello_exit);
Upvotes: 0
Views: 839
Reputation: 10020
I'm no expert in kernel programming, but you can have a look at how the current PID is retrieved for example in the code for exec()
. There seems to be a structure called current
through which you can extract the data you need. When you click on the variable name in the linked kernel source browser, you get a list of other places this variable is used.
Upvotes: 2