1,318
社区成员
发帖
与我相关
我的任务
分享
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include<linux/err.h>
#include <linux/fs.h>
#include<linux/fcntl.h>
#include<linux/unistd.h>
#include<linux/string.h>
#include<linux/time.h>
#include<linux/timex.h>
#include<linux/rtc.h>
#include<linux/types.h>
static void read(void)
{
struct file *fp;
char path[1024];
char buf1[1024];
mm_segment_t fs;
loff_t pos;
printk("hello enter/n");
sprintf(path,"/proc/%d/status",getpid());
fp = filp_open(path,O_RDWR|O_CREAT,0644);
if (IS_ERR(fp))
{
printk(KERN_ALERT "create file error/n");
}
fs =get_fs();
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
vfs_read(fp,buf1,1024, &pos);
if(strlen(buf1)!=0)
{
buf1[strlen(buf1)]='\0';
}
else
{
printk(KERN_ALERT "read error");
}
printk("read: %s/n",buf1);
filp_close(fp,NULL);
set_fs(fs);
}
static int __init read_init(void)
{
read();
printk(KERN_ALERT "init");
return 0;
}
static void __exit read_exit(void)
{
printk(KERN_ALERT "exit");
}