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

Discussion in 'Python' started by Chris Angelico, Sep 20, 2012.

  1. On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly <> 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
    Chris Angelico, Sep 20, 2012
    #1
    1. Advertising

  2. Chris Angelico

    Hans Mulder Guest

    On 20/09/12 05:11:11, Chris Angelico wrote:
    > On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly <> 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
    Hans Mulder, Sep 20, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ismael Farfán
    Replies:
    0
    Views:
    213
    Ismael Farfán
    Sep 19, 2012
  2. Ismael Farfán
    Replies:
    0
    Views:
    211
    Ismael Farfán
    Sep 19, 2012
  3. Ian Kelly
    Replies:
    0
    Views:
    238
    Ian Kelly
    Sep 19, 2012
  4. Ian Kelly
    Replies:
    0
    Views:
    232
    Ian Kelly
    Sep 19, 2012
  5. Ismael Farfán
    Replies:
    0
    Views:
    236
    Ismael Farfán
    Sep 19, 2012
Loading...

Share This Page