#include //#define THREAD_SIZE 8192
//static struct proc_dir_entry *example_dir,*foo_file;
static inline struct thread_info *get_pid_wang(void)//获取当前进程指针
{
struct thread_info *ti;
__asm__("andl %%esp,%0; ":"=r"(ti):"0"(~8191UL));
return ti;
}
int myproc(char *buf,char **start,off_t off,int count)
{
struct task_struct *task,*p;
struct list_head *pos;
int len=0;
int i=0;
//struct thread_info *ti;
task = get_pid_wang()->task;
pos=&(task->tasks);
for(pos=pos->next;pos!=&task->tasks;pos=pos->next,i++)//循环获取进程指针,并吧相关信息打印到proc下的mm文件中~
{
p=list_entry(pos,struct task_struct,tasks);
len+=sprintf(buf+len,"task:%s ",p->comm);
len+=sprintf(buf+len,"pid=%d\n",p->pid);
}
return len;
}
static int __init hello_init(void)
{
create_proc_info_entry("mm",0,NULL,myproc);//在proc下创建一个名为mm的文件~
return 0;
}
static void __exit hello_exit(void)
{
remove_proc_entry("mm",NULL);
}
module_init(hello_init);
module_exit(hello_exit);