how to open /proc file in RW mode in user mode?
hello,
I tried with following code but it doesn't work #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <string.h> int main(void) { char buf[1024]; FILE *fp; fp = fopen("/proc/my_file","rw"); if (fp == NULL) { fprintf(stderr, "Error opening file..."); exit(1); } scanf("%s",buf); fwrite(buf,strlen(buf),1,fp); printf("File Read complete\n"); fclose(fp); return 0; } My user program receives entered string but will not update it in /proc/my_file. But if i open file as w mode which eventually leads to truncate file length and write over it, that works. regards, cranium |
I think you are missing something here.
Proc files are not normal files where you write data in and get them later. Actually they are some think line an interface between user-space and kernel-space processes. Any ways for you to get whet you have written in the proc file there has to be some code in kernel-space (LKM or so) to take that data and store them in some buffer and push them to any user who tries to read that file. Finally, Hope you got my point, however it would be more helpful if you tell us what are you trying to do specifically. |
Actually i want to have something like this that user program will read/write to file that file is to be read in kenrel same time continuously by kernel module.
How to do that? |
Quote:
|
All times are GMT -5. The time now is 02:41 PM. |