[Gllug] Off Topic: C File Descriptors
John Edwards
john at cornerstonelinux.co.uk
Thu Mar 6 22:42:02 UTC 2008
On Tue, Mar 04, 2008 at 12:10:02PM +0000, Mick Farmer wrote:
> Dear GLLUGers,
>
> Is there a way of determining whether standard output and
> standard error are going to the same file/device?
Hi
Bash uses /dev/stdout and /dev/stderr, which on Linux are symlinks
to /proc/self/fd/1 and /proc/self/fd/2, which in turn point to the
device or file. Eg:
$ ls -al /proc/self/fd/[0-2]
lrwx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/0 -> /dev/pts/12
lrwx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/1 -> /dev/pts/12
lrwx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/2 -> /dev/pts/12
$ ls -al /proc/self/fd/[0-2] > /tmp/1 ; more /tmp/1
lrwx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/0 -> /dev/pts/12
l-wx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/1 -> /tmp/1
lrwx------ 1 john john 64 2008-03-06 22:38 /proc/self/fd/2 -> /dev/pts/12
$ ls -al /proc/self/fd/[0-2] > /tmp/1 2>&1 ; more /tmp/1
lrwx------ 1 john john 64 2008-03-06 22:39 /proc/self/fd/0 -> /dev/pts/12
l-wx------ 1 john john 64 2008-03-06 22:39 /proc/self/fd/1 -> /tmp/1
l-wx------ 1 john john 64 2008-03-06 22:39 /proc/self/fd/2 -> /tmp/1
HTH.
--
#---------------------------------------------------------#
| John Edwards Email: john at cornerstonelinux.co.uk |
#---------------------------------------------------------#
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20080306/da78e1f1/attachment.pgp>
-------------- next part --------------
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list