c语言实现linux的ps,c语言实现的ps功能模块

#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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值