mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-22 12:43:39 +08:00
modify list_process
This commit is contained in:
@@ -14,24 +14,7 @@
|
||||
#include <linux/sched.h>
|
||||
|
||||
|
||||
/*
|
||||
* find_task_by_pid maybe not supported
|
||||
* O(n) is fine :)
|
||||
*/
|
||||
struct task_struct * findTaskByPid(pid_t pid)
|
||||
{
|
||||
struct task_struct *task = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* show the task info
|
||||
*/
|
||||
void getTaskinfo(struct task_struct *task)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//#define METHOD 2
|
||||
static unsigned int METHOD = 1;
|
||||
@@ -39,7 +22,21 @@ module_param(METHOD, uint,0400);
|
||||
|
||||
static unsigned int PID = 1;
|
||||
module_param(PID, uint,0400);
|
||||
static int find_task_init(void)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void getTaskinfo(struct task_struct *task)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
void findTaskByPid(int pid)
|
||||
{
|
||||
struct task_struct *task = NULL, *pTask = NULL;
|
||||
struct list_head *pos = NULL;
|
||||
@@ -57,7 +54,7 @@ static int find_task_init(void)
|
||||
list_for_each(pos, &task->tasks)
|
||||
{
|
||||
pTask = list_entry(pos, struct task_struct, tasks );
|
||||
if(pTask->pid == (pid_t)PID)
|
||||
if(pTask->pid == (pid_t)pid)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask);
|
||||
break;
|
||||
@@ -69,7 +66,7 @@ static int find_task_init(void)
|
||||
method = "for_each_process";
|
||||
for_each_process(task)
|
||||
{
|
||||
if(task->pid == PID)
|
||||
if(task->pid == pid)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", task->pid, task->comm, task);
|
||||
break;
|
||||
@@ -80,7 +77,7 @@ static int find_task_init(void)
|
||||
method = "list_for_each_entry";
|
||||
list_for_each_entry(pTask, &task->tasks, tasks)
|
||||
{
|
||||
if(pTask->pid == PID)
|
||||
if(pTask->pid == (pid_t)pid)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask);
|
||||
}
|
||||
@@ -90,15 +87,20 @@ static int find_task_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void find_task_exit(void)
|
||||
static int init_find_task(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void exit_find_task(void)
|
||||
{
|
||||
printk(KERN_ALERT "GOOD BYE:find_task!!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
module_init(find_task_init);
|
||||
module_exit(find_task_exit);
|
||||
module_init(init_find_taskt);
|
||||
module_exit(exit_find_task);
|
||||
|
||||
MODULE_AUTHOR("gatieme");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*************************************************************************
|
||||
> File Name: process.c
|
||||
> Author: GatieMe
|
||||
> Mail: gatieme@163.com
|
||||
> Created Time: 2016年04月01日 星期五 21时09分29秒
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
|
||||
#include <linux/sched.h>
|
||||
|
||||
|
||||
/*
|
||||
* find_task_by_pid maybe not supported
|
||||
* O(n) is fine :)
|
||||
*/
|
||||
struct task_struct * findTaskByPid(pid_t pid)
|
||||
{
|
||||
struct task_struct *task = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* show the task info
|
||||
*/
|
||||
void getTaskinfo(struct task_struct *task)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//#define METHOD 2
|
||||
static unsigned int METHOD = 1;
|
||||
module_param(METHOD, uint,0400);
|
||||
|
||||
static unsigned int PID = 1;
|
||||
module_param(PID, uint,0400);
|
||||
static int find_task_init(void)
|
||||
{
|
||||
struct task_struct *task = NULL, *pTask = NULL;
|
||||
struct list_head *pos = NULL;
|
||||
char *method = NULL;
|
||||
|
||||
task = &init_task;
|
||||
|
||||
printk(KERN_ALERT"PID\tCOMM\tADDR\n");
|
||||
|
||||
|
||||
switch(METHOD)
|
||||
{
|
||||
case 1 :
|
||||
method = "list_for_each";
|
||||
list_for_each(pos, &task->tasks)
|
||||
{
|
||||
pTask = list_entry(pos, struct task_struct, tasks );
|
||||
if(pTask->pid == (pid_t)PID)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 2 :
|
||||
method = "for_each_process";
|
||||
for_each_process(task)
|
||||
{
|
||||
if(task->pid == PID)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", task->pid, task->comm, task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3 :
|
||||
method = "list_for_each_entry";
|
||||
list_for_each_entry(pTask, &task->tasks, tasks)
|
||||
{
|
||||
if(pTask->pid == PID)
|
||||
{
|
||||
printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
printk("the method is %s", method);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void find_task_exit(void)
|
||||
{
|
||||
printk(KERN_ALERT "GOOD BYE:find_task!!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
module_init(find_task_init);
|
||||
module_exit(find_task_exit);
|
||||
|
||||
MODULE_AUTHOR("gatieme");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -12,15 +12,20 @@
|
||||
#include <linux/moduleparam.h>
|
||||
|
||||
#include <linux/sched.h>
|
||||
//#include <asm/current.h>
|
||||
|
||||
|
||||
|
||||
//#define METHOD 2
|
||||
/*
|
||||
* you can use METHOD to select the function you want to list the process
|
||||
* METHOD = 1 "list_for_each"
|
||||
* METHOD = 2 "for_each_process"
|
||||
* METHOD = 3 "list_for_each_entry"
|
||||
*/
|
||||
static unsigned int METHOD = 1;
|
||||
module_param(METHOD, uint,0400);
|
||||
module_param(METHOD, uint, 0400);
|
||||
|
||||
static int list_process_init(void)
|
||||
|
||||
void do_list_process(void)
|
||||
{
|
||||
struct task_struct *task = NULL, *pTask = NULL;
|
||||
struct list_head *pos = 0;
|
||||
@@ -80,15 +85,24 @@ static int list_process_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void list_process_exit(void)
|
||||
|
||||
|
||||
static int init_list_process(void)
|
||||
{
|
||||
// list all the process of you system
|
||||
do_list_process( );
|
||||
}
|
||||
|
||||
static void exit_list_process(void)
|
||||
{
|
||||
printk(KERN_ALERT "GOOD BYE--list process!!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
module_init(list_process_init);
|
||||
module_exit(list_process_exit);
|
||||
module_init(init_list_process);
|
||||
module_exit(exit_list_process);
|
||||
|
||||
|
||||
MODULE_AUTHOR("gatieme");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
Reference in New Issue
Block a user