内核中的宏current,指向当前进程的task_struct结构

#include /* Needed by all modules */

#include /* Needed for KERN_* */

#include /* Needed for the macros */

#include /* Macro current point to the current process */

#include

MODULE_LICENSE("GPL");

static int hello_init(void)

{

        // current->comm是进程名, current->pid是进程PID;

        printk(KERN_WARNING "the process is \"%s\"(pid %i)\n", current->comm, current->pid);         return 0;

}

static void hello_exit(void) {

        printk("Bye, kernel!\n");

}

/* main module function */

module_init(hello_init);

module_exit(hello_exit);

你可能感兴趣的:(linux,运维,服务器)