LinuxQuestions.org
Register a domain and help support LQ
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 11-02-2009, 12:23 AM   #1
beaglebird
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Rep: Reputation: 0
How do you write to a proc file from a user program?


I know how to write to a proc file from the command line (e.g. echo hello > myProcFile) but I need to do that in a user program (written in C). I tried using fopen but it returned an error. So is there anything else I can do besides using something like execl echo?
 
Old 11-02-2009, 12:31 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
/proc is a virtual file system---physically you are just accessing data structures in memory. I would have assumed you would access it as you would any ohter file. The big difference is that writing to /proc is not something that you typically should be doing.

for something like fopen to open a file, I assume the user running the program must have the appropriate privileges. What happens if you run you program as root?
 
Old 11-02-2009, 12:50 AM   #3
beaglebird
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you for replying!

I get the same result when I run my program as root.

And to clarify, I am doing this for a school assignment. I had to make a module that creates a /proc file entry when it is initialized. The next step, which I am stuck on, is to have a user program write and read to/from the /proc file.

I thought that perhaps fopen didn't work because /proc is virtual. Or maybe I need to set permissions on the /proc file when I create it?
 
Old 11-02-2009, 01:13 AM   #4
beaglebird
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Actually, scratch that. I just realized I had coded the path of the file using '~' which obviously means different things when I'm me vs when I'm root. So that means you solved my problem. Thank you very much!
 
  


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
Write into File from Kernel and read the same file from User space saurabhchokshi Programming 0 05-01-2009 02:26 PM
I (sometimes) cant write my program file when a copy of it is running foof Linux - Newbie 6 11-13-2008 04:17 PM
A normal user now has write permissions for the whole file system 16777216 Ubuntu 2 10-23-2006 09:32 AM
how to write a batch file to make a program run during boot up in windows??? b0nd Programming 7 09-04-2006 06:16 AM


All times are GMT -5. The time now is 09:11 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration