find_task...

This commit is contained in:
gatieme
2016-05-16 16:47:43 +08:00
parent 7951a1d957
commit 07a219e1d8
4 changed files with 77 additions and 7 deletions
+29 -5
View File
@@ -1,14 +1,38 @@
obj-m := find_task.o
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
modules:
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) modules_install
clean:
make -C $(KERNELDIR) M=$(PWD) clean
.PHNOY:
modules modules_install clean
else
CFG_FLAGS += -O2 -I./
EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
# 注意:驱动模块的名字 千万 不能和本文件夹内的任何文件同名!
MODULE_NAME := find-task #指定驱动模块的名字
RESMAIN_CORE_OBJS := find_task.o #指定驱动模块的核心文件(有init 和 exit)
RESMAIN_GLUE_OBJS := get_task.o #依赖文件
#xxx-objs := 指定驱动模块的所有依赖文件
$(MODULE_NAME)-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
obj-m := find-task.o #最终由xxx-objs链接生成find-task.o,再生成find-task.ko
endif
@@ -12,6 +12,8 @@
#include <linux/sched.h>
#include "get_task.h"
/*
* macro for find_task_by_pid in the process list
* LIST_FOR_EACH to traversing the process linked list by `list_for_each`
@@ -35,12 +37,12 @@ module_param(PID, uint, 0400);
void print_vm_list(struct task_struct *task);
void getTaskinfo(struct task_struct *task)
{
}
struct task_struct* find_task_by_pid_in_rbtree(int pid)
@@ -61,6 +63,8 @@ struct task_struct* find_task_by_pid_in_ns(int pid)
{
printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, (void *)pTask);
}
return pTask;
}
@@ -152,7 +156,7 @@ static int init_find_task(void)
break;
}
}
print_vm_list(pTask);
return 0;
}
@@ -0,0 +1,34 @@
/*************************************************************************
> File Name: get_task.c
> Author: gatieme
> Created Time: Mon 16 May 2016 03:28:46 PM CST
************************************************************************/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
void print_vm_list(struct task_struct *task)
{
struct vm_area_struct *tmp = task->mm->mmap;
printk("process:%s,pid:%d\n", p->comm, p->pid);
while (tmp != NULL)
{
printk("0x%lx - 0x%lx\t",tmp->vm_start,tmp->vm_end);
(tmp->vm_flags & VM_READ) ? printk("r") : printk("-");
(tmp->vm_flags & VM_WRITE) ? printk("w") : printk("-");
(tmp->vm_flags & VM_EXEC) ? printk("x") : printk("-");
(tmp->vm_flags & VM_SHARED) ? printk("s") : printk("p");
printk("\n");
tmp = tmp->vm_next;
}
}
@@ -0,0 +1,8 @@
#ifndef __GET_TASK_H_INCLUDE__
#define __GET_TASK_H_INCLUDE__
void print_vm_list(struct task_struct *task);
#endif