LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How to get list of opened files in linux kernel programming? (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-get-list-of-opened-files-in-linux-kernel-programming-943310/)

ica07 05-04-2012 02:16 PM

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.

10x

Kustom42 05-04-2012 02:34 PM

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

Code:

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.

ica07 05-05-2012 07:18 AM

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.
10x

bsat 05-09-2012 09:52 AM

See if this helps
http://tuxthink.blogspot.in/2012/05/...f-process.html

ica07 05-13-2012 12:11 PM

@bsat
yes, that's exactly what i.m looking for. thanks a lot, you are a life saver :)


All times are GMT -5. The time now is 03:54 AM.