#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Steven");
int my_read_proc(char *page, char **start, off_t offset, int count,
int *eof, void *data);
static int __init scan_process_init(void)
{
create_proc_read_entry("steven_process", 0, NULL, my_read_proc, NULL);
return 1;
}
static void __exit scan_process_exit(void)
{
remove_proc_entry("steven_process", NULL);
return;
}
int my_read_proc(char *page, char **start, off_t offset, int count, int *eof, void *data)
{
int len = 0;
int res;
struct task_struct *p_struct;
char *buf = kmalloc(sizeof(char) * 1024, GFP_KERNEL);
if (NULL == buf)
{
printk("steven: kmalloc error!\n");
return 0;
}
memset(buf, 0, sizeof(char) * 1024);
for_each_process(p_struct)
{
len += sprintf(buf + len, "%d\t\t%d\t\t%s\n", p_struct->pid, p_struct->parent->pid, p_struct->comm);
}
res = strlen(buf);
strncpy(page, buf, res);
return res;
}
module_init(scan_process_init);
module_exit(scan_process_exit);
|