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
|