linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <Alexander.Riesen@synopsys.com>
To: Mark Atwood <mra@pobox.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: How can a process easily get a list of all it's open fd?
Date: Wed, 28 Aug 2002 10:28:45 +0200	[thread overview]
Message-ID: <20020828082845.GB16092@riesen-pc.gr05.synopsys.com> (raw)
In-Reply-To: <20020827212638.GB7541@bluemug.com>

On Tue, Aug 27, 2002 at 02:26:38PM -0700, Mike Touloumtzis wrote:
> On Tue, Aug 27, 2002 at 06:08:42PM +0200, Alex Riesen wrote:
> > tricky. You can use /proc/<getpid>/fd, and close all
> > handles listed here, but this has some caveats:
> > it's _very_ slow if you have many open files.
> > it's not portable.
> > it's not safe if you have a thread/signal handler running.
> > 
> > i never heard of a right way to do this.
> > 
> > -alex
> > 
> > int close_all_fd()
> > {
> >     char fdpath[PATH_MAX];
> >     DIR * dp;
> >     struct dirent * de;
> >     int fd;
> > 
> >     sprintf(fdpath, "/proc/%d/fd", getpid());
> >     dp = opendir(fdpath);
> 
> This can just be:
> 
> 	dp = opendir("/proc/self/fd/");
> 
> then you don't need fdpath.

Oh, indeed.

> You can use sigprocmask() if you're worried about signals coming
> in during this operation.

I, personally, strongly dislike this option.
You never know which signals are to be blocked.

Besides, it's still not portable and not safe agains threads.


-alex

  reply	other threads:[~2002-08-28  8:24 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       ` How can a process easily get a list of all it's open fd? Mark Atwood
2002-08-27 16:08         ` Alex Riesen
2002-08-27 21:26           ` Mike Touloumtzis
2002-08-28  8:28             ` Alex Riesen [this message]
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=20020828082845.GB16092@riesen-pc.gr05.synopsys.com \
    --to=alexander.riesen@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mra@pobox.com \
    /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;
as well as URLs for NNTP newsgroup(s).