Date: Sun, 24 Oct 2004 18:49:22 +0100 (BST) From: Robert Watson <rwatson@freebsd.org> To: Stephen Montgomery-Smith <stephen@math.missouri.edu> Cc: freebsd-stable@freebsd.org Subject: Re: /dev/fd/3 Message-ID: <Pine.NEB.3.96L.1041024184649.85623G-100000@fledge.watson.org> In-Reply-To: <417BE400.8090506@math.missouri.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 24 Oct 2004, Stephen Montgomery-Smith wrote:
> I have a program that needs to write to file descriptor 3 via /dev/fd/3.
> But FreeBSD-5.3 doesn't let me do that, since only fd/0-2 exist. How
> do I do this? "man fd" didn't help me.
By default, /dev/fd is services by devfs, and is initialized by
fildesc_drvinit() in kern_descrip.c. It creates a hard-coded three
entries:
dev = make_dev(&fildesc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666, "fd/0");
make_dev_alias(dev, "stdin");
dev = make_dev(&fildesc_cdevsw, 1, UID_ROOT, GID_WHEEL, 0666, "fd/1");
make_dev_alias(dev, "stdout");
dev = make_dev(&fildesc_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "fd/2");
make_dev_alias(dev, "stderr");
You can mount fdescfs on top of /dev/fd using the following command as
root:
mount -t fdescfs fdescfs /dev/fd
This will cause the number of entries in /dev/fd to correspond to the
number of file descriptors the current process has open. I'm not sure if
there are caveats associated with that approach, but from a simple
experiment here it appears to work.
Robert N M Watson FreeBSD Core Team, TrustedBSD Projects
robert@fledge.watson.org Principal Research Scientist, McAfee Research
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1041024184649.85623G-100000>
