Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to get the list of all my open file(descriptor)s and locks?

Reply
Thread Tools

Re: How to get the list of all my open file(descriptor)s and locks?

 
 
Chris Angelico
Guest
Posts: n/a
 
      09-20-2012
On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly <(E-Mail Removed)> wrote:
> You could do:
>
> os.listdir("/proc/%d/fd" % os.getpid())
>
> This should work on Linux, AIX, and Solaris, but obviously not on Windows.


I'm not sure how cross-platform it is, but at least on Linux, you can
use /proc/self as an alias for "/proc/"+os.getpid() - worth a try,
might make your code a bit easier to read.

It's documented as useful when you don't know the PID yet (eg telling
a process to read the file /proc/self/fd/0 to force it to use stdin).
So I'm confident enough to recommend testing it.

ChrisA
 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      09-20-2012
On 20/09/12 05:11:11, Chris Angelico wrote:
> On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly <(E-Mail Removed)> wrote:
>> You could do:
>>
>> os.listdir("/proc/%d/fd" % os.getpid())
>>
>> This should work on Linux, AIX, and Solaris, but obviously not on Windows.


On MacOS X, you can use

os.listdir("/dev/fd")

This might work on other OSes.

> I'm not sure how cross-platform it is, but at least on Linux, you can
> use /proc/self as an alias for "/proc/"+os.getpid() - worth a try,
> might make your code a bit easier to read.
>
> It's documented as useful when you don't know the PID yet (eg telling
> a process to read the file /proc/self/fd/0 to force it to use stdin).


At least on Linux, Solaris and MacOS X, you shouldd use /dev/stdin,
which is a symlink to whatever the official name is.
"/dev/stdin" is more readable and more portable than the official name.

> So I'm confident enough to recommend testing it.


Testing such things is the best way to learn.


Hope this helps,

-- HansM

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to get the list of all my open file(descriptor)s and locks? Ian Kelly Python 0 09-19-2012 09:40 PM
Re: How to get the list of all my open file(descriptor)s and locks? Ian Kelly Python 0 09-19-2012 09:09 PM
Re: How to get the list of all my open file(descriptor)s and locks? Ismael Farfán Python 0 09-19-2012 08:36 PM
How to get the list of all my open file(descriptor)s and locks? Ismael Farfán Python 0 09-19-2012 05:34 PM



Advertisments