LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 05-04-2012, 02:16 PM   #1
ica07
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.

10x
 
Old 05-04-2012, 02:34 PM   #2
Kustom42
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:

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.
 
Old 05-05-2012, 07:18 AM   #3
ica07
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.
10x
 
Old 05-09-2012, 09:52 AM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
See if this helps
http://tuxthink.blogspot.in/2012/05/...f-process.html
 
1 members found this post helpful.
Old 05-13-2012, 12:11 PM   #5
ica07
LQ Newbie
 
Registered: May 2012
Posts: 3

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:49 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