All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Touloumtzis <miket@bluemug.com>
To: Mark Atwood <mra@pobox.com>, linux-kernel@vger.kernel.org
Subject: Re: How can a process easily get a list of all it's open fd?
Date: Tue, 27 Aug 2002 14:26:38 -0700	[thread overview]
Message-ID: <20020827212638.GB7541@bluemug.com> (raw)
In-Reply-To: <20020827160842.GA16092@riesen-pc.gr05.synopsys.com>

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.

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

miket

  reply	other threads:[~2002-08-27 21:22 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 [this message]
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=20020827212638.GB7541@bluemug.com \
    --to=miket@bluemug.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.