Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: how to know the files opened by a process

by idsfa (Vicar)
on Dec 26, 2005 at 08:49 UTC ( [id://519085]=note: print w/replies, xml ) Need Help??


in reply to how to know the files opened by a process

For an OS that has a /proc, you can File::Find on the /proc/\d+/fd/ nodes. They will be a symlink to the opened files of each process currently running.

# ls -l /proc/####/fd/ total 3 lr-x------ 1 root root 64 Dec 26 02:46 0 -> /proc/kmsg lrwx------ 1 root root 64 Dec 26 02:46 1 -> socket:[11384] lr-x------ 1 root root 64 Dec 26 02:46 2 -> /boot/System.map-2.6.14-2- +k7

The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Replies are listed 'Best First'.
Re^2: how to know the files opened by a process
by tirwhan (Abbot) on Dec 26, 2005 at 09:38 UTC

    This will only give you the opened file descriptors for the process, it does not give you memory-mapped files(/proc/###/maps), the current working directory (/proc/###/cwd) or indeed the binary itself(/proc/###/exe). (All of these are for Linux btw, I have no idea whether this is the same on Sun OS)

    In answer to the OP's question, I once looked for the same thing and don't know of an existing module that does this. If you're looking for a cross-platform solution I'd suggest going with McDarrens suggestion to use the lsof binary and parse its output(that's what I did, I'd post code, but I don't own it and it was bog-standard parsing stuff anyway). It'll be easier to compensate for syntax and output differences of lsof than to mimic its behaviour on different platforms.


    A computer is a state machine. Threads are for people who can't program state machines. -- Alan Cox

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519085]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-03-29 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found