- 论坛徽章:
- 0
|
原帖由 guotie 于 2005-12-26 18:02 发表
这个程序在我这里测试是有问题的。
具体问题在于有时候会出现乱码,有时候正常,而且有时候出现以下错误:
** glibc detected *** double free or corruption (out): 0x0804d8c8 ***
我的系统是LFS 2. ...
这样会好一些:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xunil@bmy");
static int ps_read(char *page, char **start, off_t off,int count, int *eof, void *data)
{
int len = 0;
struct task_struct *p;
rwlock_t tasklist=RW_LOCK_UNLOCKED;
read_lock(&tasklist);
for_each_process(p)
len += sprintf(page+len,"%d\t\t%d\t\t\t%s\n",p->pid,p->parent->pid,p->comm);
read_unlock(&tasklist);
if (len <= off+count) *eof = 1;
*start = page + off;
len -= off;
if (len>count) len = count;
if (len<0) len = 0;
return len;
}
static __init int ps_init(void)
{
struct proc_dir_entry *entry;
entry = create_proc_entry("_ps", 0444, &proc_root);
if(entry == 0)
goto error;
entry->mode = S_IFREG | 0444;
entry->size = 0;
entry->read_proc = ps_read;
return 0;
error:
printk(KERN_ERR "create_proc_entry() failed !\n");
return -1;
}
static __exit void ps_cleanup(void)
{
remove_proc_entry("_ps", &proc_root);
}
module_init(ps_init);
module_exit(ps_cleanup);
[ 本帖最后由 richardhesidu 于 2005-12-27 15:08 编辑 ] |
|