?
Solved

How to access data in an existing file form a kernel module

Posted on 2003-02-25
3
Medium Priority
?
216 Views
Last Modified: 2010-04-21
Hi, I'm a newbie in programming and especially in Linux. I'm trying to write a LKM and to get it to do what I want, I need information from files in /proc. To be more precise, I need info from the 'status' file in the /proc/pid where pid is the PID of the process I need the info for. In other words, the file I need info from is constantly different.

I checked the Linux Kernel Module Programming Guide already but that has examples of using a static file in /proc that you created in the module.

Does anybody know how this can best be done, and have some (simple) examples? Like I said, I'm fairly new to C and kernel programming so the simpler the example, the better :-)

If it is not possible, some examples on how to input/output data between a user and kernelspace program through /proc in Linux 2.4 are also very appreciated.

I'm using RedHat 7.3 with a 2.4.20 kernel by the way.
0
Comment
Question by:Furrball
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 600 total points
ID: 8031139
First of all, you're way off base with the proc stuff in the Linux Kernel Module Programming Guide.  That's about how to program the other side of the file -- so someone else can read it like you want to read /proc/PID.

Reading a /proc file is the same as reading any other file.  And how to read a file from inside the kernel is about the most frequently asked question about kernel programming.  I have an example of how to do that at ftp://giraffe-data.com/pub/filewrite.c.  Actually, that's for writing to a file, but reading is analogous.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9983500
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#8031139}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question