添加了proc_create方式的用户空间代码读写程序...

This commit is contained in:
gatieme
2016-05-25 18:25:07 +08:00
parent b580ff42bd
commit b2da6ac9de
3 changed files with 122 additions and 2 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ obj-m := jif.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#KERNELDIR ?= /home/gatieme/Work/Kernel/linux-headers-3.14-desktop/
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
KERNELDIR ?= /home/gatieme/Work/Kernel/linux-headers-3.14-desktop/
PWD := $(shell pwd)
all:
+61
View File
@@ -0,0 +1,61 @@
/*************************************************************************
> File Name: test.c
> Author: gatieme
> Created Time: 2016年05月24日 星期二 19时45分38秒
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#define PROC_FILE "/proc/jif"
#define MAX_LINE 81
int main( )
{
int ret;
int procFile;
char buff[MAX_LINE];
//wait for ack signal
procFile = open(PROC_FILE, O_RDWR);
if(procFile == -1)
{
perror("Fail to open "PROC_FILE);
exit(-1);
}
else
{
printf("Open success...\n");
}
if((ret = write(procFile, "hello", strlen("hello"))) == -1)
{
perror("Fail to read "PROC_FILE);
}
else
{
printf("wriet success\n");
}
bzero(buff, sizeof(buff));
if((ret = read(procFile, buff, MAX_LINE)) == -1)
{
perror("Fail to read "PROC_FILE);
}
else
{
printf("buff = %s\n", buff);
}
close(procFile);
}
+59
View File
@@ -0,0 +1,59 @@
/*************************************************************************
> File Name: test.c
> Author: gatieme
> Created Time: 2016年05月24日 星期二 19时45分38秒
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#define PROC_FILE "/proc/jif"
#define MAX_LINE 81
int main( )
{
int ret;
int count;
int procFile;
char buff[MAX_LINE];
bzero(buff, sizeof(buff));
sprintf(buff, "echo \"hello\" > %s", PROC_FILE);
printf("%s\n", buff);
system(buff);
printf("write success...\n");
//wait for ack signal
procFile = open(PROC_FILE, O_RDONLY);
if(procFile == -1)
{
perror("Fail to open "PROC_FILE);
exit(-1);
}
else
{
printf("Open success...\n");
}
bzero(buff, sizeof(buff));
ret = read(procFile, buff, MAX_LINE);
if(ret == -1)
{
perror("Fail to read " PROC_FILE);
}
else
{
printf("buff = %s\n", buff);
}
close(procFile);
}