diff --git a/study/proc/proc_create/Makefile b/study/proc/proc_create/Makefile index 9dc31ae..22e24b3 100644 --- a/study/proc/proc_create/Makefile +++ b/study/proc/proc_create/Makefile @@ -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: diff --git a/study/proc/proc_create/test.c b/study/proc/proc_create/test.c new file mode 100644 index 0000000..19b0c12 --- /dev/null +++ b/study/proc/proc_create/test.c @@ -0,0 +1,61 @@ +/************************************************************************* + > File Name: test.c + > Author: gatieme + > Created Time: 2016年05月24日 星期二 19时45分38秒 + ************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#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); +} diff --git a/study/proc/proc_create/test2.c b/study/proc/proc_create/test2.c new file mode 100644 index 0000000..64bf943 --- /dev/null +++ b/study/proc/proc_create/test2.c @@ -0,0 +1,59 @@ +/************************************************************************* + > File Name: test.c + > Author: gatieme + > Created Time: 2016年05月24日 星期二 19时45分38秒 + ************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#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); +}