Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 05-04-2012, 03:16 PM   #1
LQ Newbie
Registered: May 2012
Posts: 3

Rep: Reputation: Disabled
How to get list of opened files in linux kernel programming?

in linux kernel programming, i want to get the path/get the files opened by a process.

i know i should look into files_struct, but i can't figure it out.
basically, what i want is a correspondent for "ps aux | grep <pid>"

any thoughts on how i should go about this?

any help is appreciated.

Old 05-04-2012, 03:34 PM   #2
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Get your pid with the ps command above then use this command:

lsof -p pid
That will give you exactly what you are looking for, lsof is list of open files. It has many options but most commonly is used with the -p and numerical pid of a process.

---------- Post added 05-04-12 at 12:35 PM ----------

On a side note you can add the 'ww' options to your ps command in addition to your aux options to see their command line options which usually include file paths, however it won't show you all open files.
Old 05-05-2012, 08:18 AM   #3
LQ Newbie
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
i actually am trying to get that in C programming.
the research i've done, points me to task_struct and files_struct, but i haven't actually seen an example of how it.s done.
Old 05-09-2012, 10:52 AM   #4
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
See if this helps
1 members found this post helpful.
Old 05-13-2012, 01:11 PM   #5
LQ Newbie
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
yes, that's exactly what i.m looking for. thanks a lot, you are a life saver


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
How many files are opened by the Kernel ? haux Linux - Server 2 09-18-2011 03:18 PM
Increase the no of Files opened titusabraham Linux - Newbie 1 10-03-2009 05:00 PM
linking multiple files kernel module programming charlotteix9 Programming 1 02-17-2009 01:28 PM
how to know the files and directories which are opened? sridhar_yerram Linux - Newbie 1 01-11-2008 03:59 AM
apache logs files can't be opened? benrose111488 Linux - Software 14 06-26-2007 01:54 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

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

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