是stdin,stdout和stderr文件吗? [英] Are stdin, stdout, and stderr Files?

查看:225
本文介绍了是stdin,stdout和stderr文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,每当一个C ++程序运行三个文件STDIN,STDOUT和STDERR打开,他给了这个链接在他的支持..

Someone told me that whenever a C++ program is run three files STDIN, STDOUT and STDERR are opened and he gave this link in his support..

http://tldp.org/LDP/abs/html/io-redirection.html

但我困惑的天气这些流实际上是文件?

But I am confused weather these streams are actually Files?


推荐答案

在POSIX系统上,流是特殊的文件描述符。 Windows有自己的err ..事情,但它们也是文件描述符。 Windows上的特殊文件的例子有标准流stdout,stdin和stderr,以及像COMn这样的可以用OpenFile()打开的串口。在Linux上,特殊文件位于/ proc和/ dev下。 / proc / cpuinfo将读回有关CPU的信息。 / dev / sdX是你的物理磁盘的句柄等。

On POSIX systems, streams are special file descriptors. Windows has its own err.. thing, but they are file descriptors there as well. Examples of special files on Windows are the standard streams stdout, stdin and stderr, as well as serial ports like COMn, which can be opened with OpenFile(). On Linux, special files are found under /proc and /dev. /proc/cpuinfo will read back information about your CPU. /dev/sdX are handles to your physical disks, etc.

那么什么是特殊文件呢?它是一个文件句柄,但内容不存储在磁盘上。文件句柄只是内核的接口。在POSIX系统上,使用open(),close(),read(),write()和ioctl()通过文件描述符与内核通信。甚至在/ dev / mem下也可以使用整个内存映射的文件描述符。

So what's a special file? It's a file handle, but the contents isn't stored on disk. The file handle is just an interface to the kernel. On POSIX systems you use open(), close(), read(), write(), and ioctl() to talk to the kernel via the file descriptor. Even a file descriptor to the whole memory map is available, under /dev/mem. You open this and pass to mmap() if you want to map a memory region for example.

不幸的是,Microsoft Windows不会处理此级别的文件描述符。我希望Windows更像POSIX样。

Unfortunately Microsoft Windows does not handle file descriptors at this level. I wish Windows was more POSIX-like.

这篇关于是stdin,stdout和stderr文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆