summaryrefslogtreecommitdiff
path: root/pid/pid.c
blob: 367eb5e3f4ffd9983744f74b42eb1620fe1bfcd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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");
MODULE_AUTHOR("Guillermo Ramos");