LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2005, 12:55 AM   #1
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Rep: Reputation: 30
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
 
Old 03-05-2005, 03:47 PM   #2
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
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.
 
Old 03-05-2005, 11:12 PM   #3
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Original Poster
Rep: Reputation: 30
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?
 
Old 03-06-2005, 03:03 AM   #4
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File Manager Super User mode Hans Troost Mandriva 3 08-19-2005 02:03 PM
Interface between user mode and kernel mode santosh_pn Linux - Software 1 06-17-2005 07:20 AM
file manager - super user mode ?? im_ka Fedora 3 02-05-2004 09:50 PM
File Manager - Super User Mode iNFERiON Linux - Newbie 1 12-23-2003 08:19 AM
Edit a file in single-user mode ricardocastro Linux - Software 2 02-26-2002 04:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration