The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mark Atwood <mra@pobox.com>
To: linux-kernel@vger.kernel.org
Subject: How can a process easily get a list of all it's open fd?
Date: 27 Aug 2002 08:34:04 -0700	[thread overview]
Message-ID: <m38z2s1fkj.fsf@khem.blackfedora.com> (raw)
In-Reply-To: <200208270138.g7R1ckGx001985@eeyore.valparaiso.cl>


I need to close all the none std[in|out|err] open fd's.

I've been told to do it like so:

  {
    int i;
    for (i=3; i<OPEN_MAX; i++)
      close(i);
  }

This is very slow, plus I have discovered that I can have open fd's with
values greater than OPEN_MAX.

I thought about getting the max fd from rlimit, but that doesn't work
either.  Say I have a rlimit of 1024 open fd's, and I open numbers 3
thru 1023, then I close 3 thru 1022, then I set the rlimit down to
16. rlimit then returns 16, but the largest open fd is still 1023.

So that doesn't work.

And I still have the problem that looping between 3 and whatever I pick
as the top and calling close on each in turn is very slow.

So what's the "right way" to do it?

I would *love* for there to be an ioctl or some syscall that I could
pass a pointer to an int and a pointer to an int array, and it would
come back telling me how many open fd's I've got, and fill in the
array with those fd's.

-- 
Mark Atwood   | Well done is better than well said.
mra@pobox.com | 
http://www.pobox.com/~mra

  parent reply	other threads:[~2002-08-27 15:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-26 20:06 [PATCH] make raid5 checksums preempt-safe Robert Love
2002-08-26 21:09 ` Thunder from the hill
2002-08-26 21:15   ` Robert Love
2002-08-27  1:38     ` Horst von Brand
2002-08-27 15:25       ` Thunder from the hill
2002-08-27 15:34       ` Mark Atwood [this message]
2002-08-27 16:08         ` How can a process easily get a list of all it's open fd? Alex Riesen
2002-08-27 21:26           ` Mike Touloumtzis
2002-08-28  8:28             ` Alex Riesen
2002-08-27 23:21         ` DervishD
2002-08-26 22:33 ` [PATCH] make raid5 checksums preempt-safe Brian Gerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m38z2s1fkj.fsf@khem.blackfedora.com \
    --to=mra@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox