LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to open /proc file in RW mode in user mode? (https://www.linuxquestions.org/questions/programming-9/how-to-open-proc-file-in-rw-mode-in-user-mode-297840/)

cranium2004 03-05-2005 12:55 AM

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

gr33ndata 03-05-2005 03:47 PM

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.

cranium2004 03-05-2005 11:12 PM

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?

r0b0 03-06-2005 03:03 AM

Quote:

Originally posted by cranium2004
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?

Create the file from the kernel module and then open it from the user space app. User space apps cannot create new files in /proc.


All times are GMT -5. The time now is 02:41 PM.