diff options
Diffstat (limited to 'pid')
-rw-r--r-- | pid/Makefile | 7 | ||||
-rw-r--r-- | pid/pid.c | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/pid/Makefile b/pid/Makefile new file mode 100644 index 0000000..b9e7cfd --- /dev/null +++ b/pid/Makefile @@ -0,0 +1,7 @@ +obj-m += pid.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/pid/pid.c b/pid/pid.c new file mode 100644 index 0000000..b930fe6 --- /dev/null +++ b/pid/pid.c @@ -0,0 +1,34 @@ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/sched.h> + +static char modname[] = "pid.ko"; +static struct task_struct *mytask; +static struct task_struct *parent; + +static int __init init(void) +{ + mytask = current; + printk(KERN_ALERT "%s loaded by %s (%d)\n", + modname, mytask->comm, mytask->pid); + parent = mytask->parent; + while (mytask->pid != parent->pid) { + printk(KERN_ALERT "current: %s (%d) - parent: %s (%d)\n", + mytask->comm, mytask->pid, parent->comm, parent->pid); + mytask = mytask->parent; + parent = mytask->parent; + } + + return 0; +} + +static void __exit exit(void) +{ + printk(KERN_ALERT "%s unloaded\n", modname); +} + +module_init(init); +module_exit(exit); + +MODULE_LICENSE("GPL"); |